nestjs-jwt-authorize
TypeScript icon, indicating that this package has built-in type declarations

2.0.2 • Public • Published

nestjs jwt authorize

Description

NestJS package to authorize by role from JWT.

It is designed to work in Kubernetes cluster with Istio

Decorators:

  • for methods:
    • HasRole(roles)
      • e.g @HasRole('ADMIN', 'SYS')
    • IsPublic()
  • for parameters
    • GetUser()
      • returns User object or throws UserNotFoundException

Installation

$ npm i nestjs-jwt-authorize

NestJS module:

providers: [
    {
      provide: AUTHORIZATION_HEADER_NAME,
      useValue: 'x-authz'
    },
    {
      provide: APP_GUARD,
      useClass: RolesGuard,
    },
  ]

export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer): any {
    consumer.apply(AuthenticationMiddleware).forRoutes('*');
  }
}

Test

# unit tests
$ npm run test

# tests coverage
$ npm run test:cov

Readme

Keywords

none

Package Sidebar

Install

npm i nestjs-jwt-authorize

Weekly Downloads

0

Version

2.0.2

License

APACHE 2.0

Unpacked Size

121 kB

Total Files

37

Last publish

Collaborators

  • w473