0.2.0 • Published 2 years ago

nest-keycloak-grpc v0.2.0

Weekly downloads
-
License
-
Repository
github
Last release
2 years ago

Nest-Keycloak

Keycloak Connect GRPC wrapper for NestJS

Configuration

This library is configured using environment variables

  • KEYCLOAK_BASE_URL
  • KEYCLOAK_REALM
  • KEYCLOAK_CLIENT_ID
  • KEYCLOAK_CLIENT_SECRET

Usage

import { KeycloakGrpcConnectModule } from 'nest-keycloak-grpc';
import { ConfigModule } from '@nestjs/config';

@Module({
     imports: [
          ConfigModule,
          KeycloakGrpcConnectModule,
     ],
     // ...
})
export class ExampleModule {}

Add KeycloakGrpcConnectModule and ConfigModule to your modules imports array.

Guards

  • ProtectedGuard
  • RoleGuard

These guards should be used in the order above according to the Binding Guards documentation.

Decorators

  • Mandate Authentication - MethodDecorator @Protected() Depends on the ProtectedGuard
  • Check Role - RouteParamDecorator @Role('permission') Depends on the RoleGuard

NB: Roles on Keycloak are actually implemented as permissions. Permissions mean multiple different things in Keycloak. Keycloak User Groups can be used in place of the common idea of Roles.

Todo

  • Make all keycloak options env-configurable (e.g token audience verification )