A Frontend Javascript service that integrates with the Keycloak authentication service, guiding users to a login portal when a 401 Unauthorised response is received from an API.
$ npm i keycloak-redirect
Import the package, then use the object exposed to return the function authenticate
, passing in all mandatory arguments: a config object, a XMLHttpRequest object, and window.
import keycloakRedirect from 'keycloak-redirect';
var config = {
backend: "http://yourBackendUrl.com",
clientId: "yourClientId",
keycloakUrl: "http://yourKeycloakUrl.com"
};
keycloakRedirect.authenticate(config, new XMLHttpRequest(), $window);
$ npm test
$ npm run compile