@darren_gannon/auth0
v1.0.18
Published
A library to connect nestjs to auth0
Readme
darren_gannon/auth0
Install
npm i @darren_gannon/auth0Usage
Import AuthzModule in AppModule
@Module({
imports: [
Auth0Module.register({
issuer: string
audience: string
extractUserPermissions: (context: ExecutionContext) => string[]
mapRequiredPermissions?: (permissions: string[], context: ExecutionContext) => string[]
}),
],
})
export class AppModule {}Attach the AuthzGuard
This can be done either directly on the global scope or on a request handler
Globally
@Module({
providers: [
{
provide: APP_GUARD,
useClass: AuthzGuard,
},
],
})
export class AppModule {}Per request handler
@UseGuards(AuthzGuard)
@Controller()
export class AppController {
@Get()
getDate(): string {
return new Date().toISOString();
}
}Validate Permissions
Define the required permissions
This can be done at a class and method scope
Class scope
@Permissions("permission_str")
export class AppController { }Method scope
export class AppController {
@Permissions("permission_str")
@Get()
getHello() {
return "Hello World!"
}
}