Keycloak client and admin provider for Nest.js applications with built-in User Managed Access (UMA) and ACL support.
Keycloak client and admin provider for Nest.js applications with built-in User Managed Access (UMA) and ACL support.
Install using npm i --save nestjs-keycloak-admin or pnpm add nestjs-keycloak-admin
@keycloak/keycloak-admin-client package, nestjs-keycloak-admin can't support CommonJS at the moment.
The team behind keycloak-admin-client made the decision to have a breaking change and support CommonJS.
Please refer to this Github issue for more information about their decision-making process.Then on your app.module.ts
…By default nestjs-keycloak-admin supports User Managed Access for managing your resources.
…@Get('/hello')
@Roles({roles: ['realm:admin'], mode: RoleMatchingMode.ANY})
sayHello(@User() user: KeycloakUser, @AccessToken() accessToken): string {
return `life is short. -${user.email}/${accessToken}`
}Here is the decorators you can use in your controllers.
| Decorator | Description |
|---|---|
| @User | Retrieves the current Keycloak logged-in user. (must be per method, unless controller is request scoped.) |
| @AccessToken | Retrieves the current access token. (must be per method, unless controller is request scoped.) |
| @DefineResource | Define the keycloak application resource name. |
| @DefineScope | Define the keycloak resource scope (ex: 'create', 'read', 'update', 'delete') |
| @EnforceResource | |
| @FetchResources | |
| @Public | Allow any user to use the route. |
| @Roles | Keycloak realm/application roles. Prefix any realm-level roles with "realm:" (i.e realm:admin) |
No open issues yet, or sync has not completed.