Skip to content
Snippets Groups Projects
Commit 4407ff28 authored by Alexandre Bourlier's avatar Alexandre Bourlier
Browse files

Improved OIDC client connect script

parent de33cc78
No related branches found
No related tags found
No related merge requests found
......@@ -16,20 +16,40 @@ sib.oidc._setup = function(settings) {
}
// Retrieve User from sessionStorage, or fetch it
sib.oidc._getUser = function() {
sib.oidc._manager.getUser()
.then(function(user) {
if (user == null) {
sib.oidc._manager.signinRedirectCallback()
.then()
.catch(function(error) {
sib.oidc._manager.signinRedirect({state: "dummy data"})
.then()
.catch(function(error) {
console.log(error);
});
});
}
else {
sib.oidc.user = user;
}
})
.catch(function(error) {
console.log(error);
});
}
// Connect to OIDC provider
sib.oidc.connect = function (settings) {
sib.oidc._connect = function(settings) {
sib.oidc._setup(settings);
sib.oidc._getUser();
sib.oidc._manager.signinRedirectCallback()
.then()
.catch(function(error) {
console.log(error);
sib.oidc._manager.signinRedirect({state: "some data"})
.then()
.catch(function(error) {
console.log(error);
});
// When user loaded...
sib.oidc._manager.events.addUserLoaded(function(user) {
sib.oidc._getUser();
});
}
......@@ -37,5 +57,5 @@ sib.oidc.connect = function (settings) {
// Entry point
fetch("./oidc-client-config.json")
.then(response => response.json())
.then(settings => sib.oidc.connect(settings));
.then(settings => sib.oidc._connect(settings));
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment