62 lines
1.3 KiB
JavaScript
62 lines
1.3 KiB
JavaScript
if (typeof Oidc == "undefined") {
|
|
throw new Error("You are missing the `oidc-client-js` lib");
|
|
}
|
|
|
|
|
|
// Var declarations
|
|
var sib = {};
|
|
sib.oidc = {};
|
|
|
|
|
|
// Setup User Manager
|
|
sib.oidc._setup = function(settings) {
|
|
if (typeof sib.oidc._manager == "undefined") {
|
|
sib.oidc._manager = new Oidc.UserManager(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._setup(settings);
|
|
sib.oidc._getUser();
|
|
|
|
|
|
// When user loaded...
|
|
sib.oidc._manager.events.addUserLoaded(function(user) {
|
|
sib.oidc._getUser();
|
|
});
|
|
}
|
|
|
|
|
|
// Entry point
|
|
fetch("./oidc-client-config.json")
|
|
.then(response => response.json())
|
|
.then(settings => sib.oidc._connect(settings));
|
|
|