Skip to content

Commit

Permalink
try check-sso
Browse files Browse the repository at this point in the history
  • Loading branch information
zivglik committed Feb 3, 2025
1 parent 71c4b53 commit 8bcfc4d
Showing 1 changed file with 31 additions and 48 deletions.
79 changes: 31 additions & 48 deletions src/keycloak/keycloakServices.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable import/no-unresolved */
import Keycloak from 'keycloak-js';

/*
const KeycloakConfig = {
clientId: 'simulator-ui-app',
realm: 'Hkube',
Expand All @@ -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",
Expand All @@ -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);
Expand Down

0 comments on commit 8bcfc4d

Please sign in to comment.