Client implementation for the EVVA Auth Service.
npm i @evva/nest-auth-client
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;
}
}
# Nest Build
$ nest build