0.0.3 • Published 5 years ago
@ramble-inc/nest-grpc-authz v0.0.3
@ramble-inc/nest-grpc-authz
Getting Started
Installation
Using yarn
yarn add @ramble-inc/nest-authzor using npm
npm i --save @ramble-inc/nest-authzUse Guard
Set global guard
AuthGuard depends on AuthService , so import AuthModule .
NOTE
Do not use useGlobalGuards() because cannot inject dependencies to guard.
See https://docs.nestjs.com/guards#binding-guards[NestJS official documents]
@Module({
imports: [
AuthModule.forRoot({
jwksUri: 'https://example.com/.well-known/jwks.json',
clientId: 'client_id',
issuerUri: 'https://example.com/',
}),
],
providers: [
{
provide: APP_GUARD,
useClass: AuthGuard,
},
],
})
export class AppModule {}or set options with ConfigService
@Module({
imports: [
AuthModule.forRootAsync({
useFactory: (configService: ConfigService) => {
return {
jwksUri: configService.get('JWKS_URI'),
clientId: configService.get('CLIENT_ID'),
issuerUri: configService.get('ISSUER_URI'),
};
},
imports: [ConfigModule],
inject: [ConfigService],
}),
],
providers: [
{
provide: APP_GUARD,
useClass: AuthGuard,
},
],
})
export class AppModule {}Get decoded JWT payload
AuthGuard adds entire JWT payload to metadata. +
You can safely get JWT payload by using isMetadataWithClaim (Type Guard).
if (isMetadataWithClaim(metadata)) {
const { claim } = metadata;
}