Skip to content

Latest commit

 

History

History
81 lines (66 loc) · 2.79 KB

README.md

File metadata and controls

81 lines (66 loc) · 2.79 KB

Nest Auth Client

NPM Version NPM Downloads NPM Unpacked Size (with version) GitHub last commit GitHub branch check runs EVVA License

Client implementation for the EVVA Auth Service.

Install

npm i @evva/nest-auth-client

Usage

import { ConfigModule, ConfigService } from '@nestjs/config';
import {
  AUTH_CLIENT,
  AUTH_ENDPOINT,
  AUTH_SECRET,
  AUTH_TENANT,
  AUTH_VALIDITY,
  AuthClientModule,
  AuthClientModuleOptions,
  VAULT_CA,
  VAULT_ENDPOINT,
  VAULT_JWTROLE_IDENTIFIER,
} from '@evva/nest-auth-client';

@Module({
  imports: [
    AuthClientModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: async (configService: ConfigService) =>
        ({
          authEndpoint: configService.get<string>(AUTH_ENDPOINT), //use optional
          authTenant: configService.get<string>(AUTH_TENANT),
          authClientId: configService.get<string>(AUTH_CLIENT),
          authClientSecret: configService.get<string>(AUTH_SECRET),
          authValidity: parseInt(configService.get(AUTH_VALIDITY)), // in seconds, see spec
          vaultRoleId: configService.get<string>(VAULT_JWTROLE_IDENTIFIER),
          vaultEndpoint: configService.get<string>(VAULT_ENDPOINT),
          vaultCA: configService.get<string>(VAULT_CA),
        }) as AuthClientModuleOptions,
    }),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

When using the ConfigService, make sure that the variables are loaded before accessing them. This usually works as follows:

export class MyModule implements OnModuleInit {
  
  
  async onModuleInit() {
    await ConfigModule.envVariablesLoaded;
  }
}

Build & Package

# Nest Build
$ nest build

Support

Stay in touch

License

Proprietary