Skip to content

USACE/keycloak-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#Simple Keycloak JS Client

to use, add the keycloak js class to your project and import it into your auth bundle. then in the bundler init function, set keycloak up similar to the code below.

refreshUrl was added to support the use case when a token is requested via CAC, then refreshed on the keycloak server's non-cac route to avoid re-entering PIN numbers.

npm install @usace/keycloak

import Keycloak from "@usace/keycloak"

init:store=>{
    keycloak = new Keycloak({
      keycloakUrl:keycloakHost,
      refreshUrl:keycloakRefresh, //omit if refresh should use keycloakHost
      realm:keycloakRealm,
      client:keycloakClient,
      redirectUrl:keycloakRedirect,
      refreshInterval:300,
      sessionEndWarning:600,
      onAuthenticate:(token)=>{
        store.doAuthUpdate(token);
      },
      onError:(err)=>{
        console.log(err);
        store.doAuthUpdate(null);
      },
      onSessionEnding:(remainingTime)=>{
        console.log(remainingTime);
        store.doAppUpdateNotification(true,"warning",`Your session is expiring in ${Math.round(remainingTime/60)} minutes.`)
      }
    });

    keycloak.checkForSession();
  },

This package is automatically published to NPM when a new release is created. Use npm version to update the version of the package prior to running a new release.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published