0.5.0 • Published 2 years ago

@dev-jo/authentication-lib v0.5.0

Weekly downloads
-
License
ISC
Repository
gitlab
Last release
2 years ago

Description

Library with RBAC for Bupa. It means to be used with Azure AD. It is upload to npm as "Library Name". In the project you can try it with the server.

Installation

$ yarn

Running the app to test RBAC

# development
$ yarn start

# watch mode
$ yarn start:dev

# production mode
$ yarn start:prod

Using the Auth modules

// It is needed to import AuthzModule to configure Passport.js to verify access token from azure
// Example using clientId and tenantId from configuration file
  AuthzModule.forRoot({
    clientId: configuration().azure.clientId,
    tenantId: configuration().azure.tenantId,
    logLevel: configuration().azure.logLevel,
  }, configuration().azure.rolesKey),

// Then we can use AuthGuard to guard a route or controller
  import { AuthGuard } from '@nestjs/passport';
  @UseGuards(AuthGuard('oauth-bearer'))

// Can use PermissionGuard if you need to protect a route with specific permission set as metadata with decorator @Permissions
  @UseGuards(AuthGuard('oauth-bearer'), PermissionsGuard)
  @Permissions('write:example-permission')

// Can use RolesGuard if you need to protect a route with specific role set as metadata with decorator @Roles
  @UseGuards(AuthGuard('oauth-bearer'), RolesGuard)
  @Roles('read:permission')

Test

# unit tests
$ yarn test

# test coverage
$ yarn test:cov

Environment variable

NameRequiredExample
PORTNo3000
AZURE_CLIENT_IDYesuri
AZURE_TENANT_IDYesuri
AZURE_ROLES_KEYYesroles
AZURE_LOG_LEVELYes'info' or false