@libstack/keycloak
Add keycloak integration to your @libstack/server
.
Keycloak: https://www.keycloak.org/
Installing
npm install @libstack/keycloak --save
New env variables
KEYCLOAK_ENABLED
: Must be true to enable the integrationKEYCLOAK_AUTH_URL
: This is the auth url for keycloak authorizationKEYCLOAK_CLIENT_ID
: The client ID to useKEYCLOAK_CLIENT_SECRET
: The client Secret to useKEYCLOAK_REALM
: The keycloak realm
Integrate to your routes
In order to enable integration, your routes need to have a custom property { roles: ['admin'] }
Where roles will be the client resource roles.
So, we recommend on creating realm-roles on your keycloak and having them as composite with the client roles. You will assign the realm-roles to your users.
Sample code
import { GET, RestController } from '@libstack/server';
@RestController('/v1/test')
class TestRouter {
@GET('/unauthorized')
async unauthorizedRoute():Promise<any> {
return { authorized: false };
}
@GET('/authorized', { roles: ['admin'] })
async authorizedRoute():Promise<any> {
return { authorized: true };
}
}