src/index.js
//to get user infos on client side
to get user infos on client side
to get user infos on client side
function keycloakLogin() {
  var keycloak = Keycloak({
    url: config.keycloakUrl,
    realm: config.realm,
    clientId: config.clientId,
    credentials: {
      secret: '261c186e-7084-4533-9c13-d2ae97e9a1ac'
    }
  });
  keycloak.init({ onLoad: 'login-required', checkLoginIframe: false }).success(authenticated => {
    if (authenticated) {
      console.log(JSON.stringify(keycloak))
      store.getState().keycloak = {token: keycloak.token, logout: keycloak.logout}
      console.log("kc " + JSON.stringify(keycloak.idTokenParsed))
      store.getState().current_user = getUser(keycloak.idTokenParsed)
      setInterval(() => {
        keycloak.updateToken(30).success(function (refreshed) {
            if(refreshed) {
              store.getState().keycloak = {token: keycloak.token, logout: keycloak.logout}
              store.getState().current_user = getUser(keycloak.idTokenParsed)
            }
          }).error(function () {
            alert('Your session has expired, please log in again');
            keycloak.logout();
          })
        }, 10000);
      displayPage();
    }
  }).error(function (error) {
    console.log(error);
    console.log("Authentication error. Check Keycloak params and cors issues.");
  });
}
function keycloakLogin ( ) { var keycloak = Keycloak ( { url : config . keycloakUrl , realm : config . realm , clientId : config . clientId , credentials : { secret : '261c186e-7084-4533-9c13-d2ae97e9a1ac' } } ) ; keycloak . init ( { onLoad : 'login-required' , checkLoginIframe : false } ) . success ( authenticated => { if ( authenticated ) { console . log ( JSON . stringify ( keycloak ) ) store . getState ( ) . keycloak = { token : keycloak . token , logout : keycloak . logout } console . log ( "kc " + JSON . stringify ( keycloak . idTokenParsed ) ) store . getState ( ) . current_user = getUser ( keycloak . idTokenParsed ) setInterval ( ( ) => { keycloak . updateToken ( 30 ) . success ( function ( refreshed ) { if ( refreshed ) { store . getState ( ) . keycloak = { token : keycloak . token , logout : keycloak . logout } store . getState ( ) . current_user = getUser ( keycloak . idTokenParsed ) } } ) . error ( function ( ) { alert ( 'Your session has expired, please log in again' ) ; keycloak . logout ( ) ; } ) } , 10000 ) ; displayPage ( ) ; } } ) . error ( function ( error ) { console . log ( error ) ; console . log ( "Authentication error. Check Keycloak params and cors issues." ) ; } ) ; }
to get user infos on client side
to get user infos on client side
//getUser(keycloak.idTokenParsed.sub)(store.dispatch)