Commit 5ac9d61e authored by Alexandre's avatar Alexandre

Auto login script if not logged in already

parents
# SIB OIDC
Allows your users to login via a given OIDC provider.
## Installation
Add the following within the `<head>` of your HTML :
```html
<script src="https://cdn.happy-dev.fr/oidc-client/oidc-client.min.js"></script>
<script src="http://path.to/sib-oidc.js"
data-authority="https://some-oidc-provider.gold/openid/"
data-client_id="833925"
data-redirect_uri="http://my-app.gold"
data-response_type="id_token token"
data-scope="openid profile email"
data-automaticSilentRenew="true"
data-loadUserInfo="true"
></script>
```
## Configuration
See [the available properties here](https://github.com/IdentityModel/oidc-client-js/wiki#usermanager)
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
console.log(document.currentScript.dataset);
sib.oidc._connect(document.currentScript.dataset);
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