1.1.0 • Published 3 years ago
kommonitor-keycloak-helper v1.1.0
keycloak-helper
a small helper service for NodeJS apps to authenticate to Keycloak
usage hints
Use it in two steps.
- install in node app directly from github
npm install --save https://github.com/KomMonitor/keycloak-helper
- require helper service
let keycloakHelperService = require('kommonitor-keycloak-helper');
- initialize helper service parameters required to perform keycloak authentication services
keycloakHelperService.initKeycloakHelper(authServerUrl, realm, clientId, clientSecret, kommonitorAdminUsername, kommonitorAdminUserPassword, kommonitorAdminRolename)
perform authentication action, by either calling
requestAccessToken()
to request an access token as a KomMonitor Admin usergetRolesFromKeycloakToken(token)
to request role names of a valid submitted keycloak tokenisAdminUser(token)
to request whether the submitted keycloak token resolves to a user with KomMonitor admin rightscheckKeycloakProtection(req, res, next, method)
as express middleware in order to intercept any incoming requests and perform keycloak protection checks for KomMonitor i.e. as should be integrated as the first middleware when instantiating express like so:
let app = express(); app.use(async function(req, res, next) { // intercept requests to perform any keycloak protection checks. await keycloakHelperService.checkKeycloakProtection(req, res, next, "POST"); });
1.1.0
3 years ago