diff --git a/src/keycloak/keycloakServices.js b/src/keycloak/keycloakServices.js index fbbb33992..01a4abf44 100644 --- a/src/keycloak/keycloakServices.js +++ b/src/keycloak/keycloakServices.js @@ -1,6 +1,6 @@ /* eslint-disable import/no-unresolved */ import Keycloak from 'keycloak-js'; - +/* const KeycloakConfig = { clientId: 'simulator-ui-app', realm: 'Hkube', @@ -15,6 +15,18 @@ const KeycloakConfig = { checkLoginIframe: true, checkLoginIframeInterval: 30, }; +*/ +const KeycloakConfig2 = { + clientId: 'simulator-ui-app-local', + realm: 'Hkube', + // 'auth-server-url': 'https://cicd.hkube.org/hkube/keycloak', + url: 'https://cicd.hkube.org/hkube/keycloak', + // 'ssl-required': 'external', + // resource: 'simulator-ui-app-local', + // 'public-client': true, + // 'confidential-port': 0, + // clientUId: '4e1e803b-8e46-4418-a87d-6e8846a01edc', +}; /* "realm": "Hkube", @@ -25,55 +37,26 @@ const KeycloakConfig = { "confidential-port": 0 */ -const _kc = new Keycloak(KeycloakConfig); - -const storedToken = localStorage.getItem('kcToken'); -const storedRefreshToken = localStorage.getItem('kcRefreshToken'); +const _kc = new Keycloak(KeycloakConfig2); const initKeycloak = (appToRender, renderError) => { - if (storedToken && storedRefreshToken) { - _kc - .init({ - onLoad: 'login-required', - }) - .then(authenticated => { - // eslint-disable-next-line no-debugger - debugger; - if (!authenticated) { - console.log('user is not authenticated..!'); - } else { - _kc.token = storedToken; - _kc.refreshToken = storedRefreshToken; - } - - appToRender(); - }) - .catch(authenticatedError => { - console.error(authenticatedError); - return renderError(authenticatedError); - }); - } else { - _kc - .init({ - onLoad: 'login-required', - }) - .then(authenticated => { - // eslint-disable-next-line no-debugger - debugger; - if (!authenticated) { - console.log('user is not authenticated..!'); - } - - localStorage.setItem('kcToken', _kc.token); - localStorage.setItem('kcRefreshToken', _kc.refreshToken); - - appToRender(); - }) - .catch(authenticatedError => { - console.error(authenticatedError); - return renderError(authenticatedError); - }); - } + _kc + .init({ + onLoad: 'check-sso', + silentCheckSsoRedirectUri: `${window.location.origin}/silent-check-sso.html`, + pkceMethod: 'S256', + }) + .then(authenticated => { + if (!authenticated) { + console.log('user is not authenticated..!'); + } + + appToRender(); + }) + .catch(authenticatedError => { + console.error(authenticatedError); + return renderError(authenticatedError); + }); }; const doLogin = _kc.login.bind(_kc);