🩹 Allow Keycloak authentication to pass 'IdP Hint'
* add App Config option for 'IdP Hint' under Keycloak Authentication * refactor the authentication trigger mechanism to allow direct call to keyjclaok-js adapter login() function * remove `onLoad` from construction options (as it belongs to init())
This commit is contained in:
@@ -13,25 +13,25 @@ class KeycloakAuth {
|
||||
constructor() {
|
||||
const { auth } = getAppConfig();
|
||||
const {
|
||||
serverUrl, realm, clientId, legacySupport,
|
||||
serverUrl, realm, clientId, idpHint, legacySupport,
|
||||
} = auth.keycloak;
|
||||
const url = legacySupport ? `${serverUrl}/auth` : serverUrl;
|
||||
const initOptions = {
|
||||
url, realm, clientId, onLoad: 'login-required',
|
||||
};
|
||||
const initOptions = { url, realm, clientId };
|
||||
const loginOptions = idpHint ? { idpHint } : {};
|
||||
|
||||
this.loginOptions = loginOptions;
|
||||
this.keycloakClient = Keycloak(initOptions);
|
||||
}
|
||||
|
||||
login() {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.keycloakClient.init({ onLoad: 'login-required' })
|
||||
this.keycloakClient.init({ onLoad: 'check-sso' })
|
||||
.then((auth) => {
|
||||
if (auth) {
|
||||
this.storeKeycloakInfo();
|
||||
return resolve();
|
||||
} else {
|
||||
return reject(new Error('Not authenticated'));
|
||||
return this.keycloakClient.login(this.loginOptions);
|
||||
}
|
||||
})
|
||||
.catch((reason) => reject(reason));
|
||||
|
||||
Reference in New Issue
Block a user