keycloak-roles-connect
Connect-like middleware for authorization and roles management.
This module can be easily extended to handler any kind of JWT roles specification by client.
However the base config and implementation takes in consideration the keyclock:Oauth2 generated
roles in the JWT.
This middleware does NOT
verify
JWT tokens, it is intended to be use for services that stand behind anapi-gateway
orproxy
that handles the JWT token verification.
Basic Usage
const middleware protect = app // middleware based role checkapp // middleware based roles check for the clientapp // middleware based role check for custom clientconst clientId = 'yourclientid'app // programmatic client role checkapp // programmatic custom client role checkapp // programmatic custom client roles checkapp
Setting up and extending the Auth class for custom use cases
//Adding custome roles for the applicationconst ROLES = SYS_ADMIN: 'sys-admin' USER: 'user' REVIEWER: 'reviewer' //Keycloack client idconst CLIENT_ID = 'client-app' const KConnect = const Auth = KConnect /** * Extending Auth class to add isReviewer method and overwriting * the default behavior of isSysAdmin.*/ { return this } { return this } moduleexports = KConnect
Checks Shortcuts