Commit 45e0f181 authored by Nicolas Mérigot's avatar Nicolas Mérigot

fix: avoid infinite call

parent 1e213581
Pipeline #1995 passed with stage
in 37 seconds
......@@ -17,6 +17,7 @@ class SIBOidc extends HTMLElement {
this.user = null;
// duplicate default settings in this.settings
this.settings = Object.assign({}, defaultSettings);
this.oidcStatus = 'idle';
}
async connectedCallback() {
......@@ -55,23 +56,30 @@ class SIBOidc extends HTMLElement {
}
// try to get user through OIDC Manager
const user = await this.manager.getUser();
let user = await this.manager.getUser();
if (user) {
this.user = user;
return user;
}
try {
const user = await this.manager.signinRedirectCallback();
location.href = user.state;
return user;
} catch (e) {
this.manager.signinRedirect({
state: location.href,
});
throw `Can't get user, redirect to OIDC authority ${this.settings.authority}`;
if (this.oidcStatus === 'idle') {
this.oidcStatus = 'working';
try {
user = await this.manager.signinRedirectCallback();
location.href = decodeURIComponent(user.state.url);
return user;
} catch(e) {
console.log(e);
await this.manager.signinRedirect({
state: {
url: encodeURIComponent(location.href),
},
});
throw `Can't get user, redirect to OIDC authority ${this.settings.authority}`;
}
}
return undefined;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment