mirror of
https://github.com/Lissy93/dashy.git
synced 2024-12-27 02:43:55 +03:00
🩹 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:
parent
3e7b51da33
commit
d9740427eb
@ -481,6 +481,11 @@
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "The Client ID of the client you created for use with Dashy"
|
"description": "The Client ID of the client you created for use with Dashy"
|
||||||
},
|
},
|
||||||
|
"idpHint": {
|
||||||
|
"title" : "IdP hint",
|
||||||
|
"type": "string",
|
||||||
|
"description": "Set to the 'Alias' of an existing Identity Provider in the specified realm to skip the Keycloak login page and redirect straight to the external IdP for authentication"
|
||||||
|
},
|
||||||
"legacySupport": {
|
"legacySupport": {
|
||||||
"title": "Legacy Support",
|
"title": "Legacy Support",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
|
@ -13,25 +13,25 @@ class KeycloakAuth {
|
|||||||
constructor() {
|
constructor() {
|
||||||
const { auth } = getAppConfig();
|
const { auth } = getAppConfig();
|
||||||
const {
|
const {
|
||||||
serverUrl, realm, clientId, legacySupport,
|
serverUrl, realm, clientId, idpHint, legacySupport,
|
||||||
} = auth.keycloak;
|
} = auth.keycloak;
|
||||||
const url = legacySupport ? `${serverUrl}/auth` : serverUrl;
|
const url = legacySupport ? `${serverUrl}/auth` : serverUrl;
|
||||||
const initOptions = {
|
const initOptions = { url, realm, clientId };
|
||||||
url, realm, clientId, onLoad: 'login-required',
|
const loginOptions = idpHint ? { idpHint } : {};
|
||||||
};
|
|
||||||
|
|
||||||
|
this.loginOptions = loginOptions;
|
||||||
this.keycloakClient = Keycloak(initOptions);
|
this.keycloakClient = Keycloak(initOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
login() {
|
login() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.keycloakClient.init({ onLoad: 'login-required' })
|
this.keycloakClient.init({ onLoad: 'check-sso' })
|
||||||
.then((auth) => {
|
.then((auth) => {
|
||||||
if (auth) {
|
if (auth) {
|
||||||
this.storeKeycloakInfo();
|
this.storeKeycloakInfo();
|
||||||
return resolve();
|
return resolve();
|
||||||
} else {
|
} else {
|
||||||
return reject(new Error('Not authenticated'));
|
return this.keycloakClient.login(this.loginOptions);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((reason) => reject(reason));
|
.catch((reason) => reject(reason));
|
||||||
|
Loading…
Reference in New Issue
Block a user