forked from sahawut/example-midas-sso-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.js
32 lines (29 loc) · 1.18 KB
/
login.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
window.addEventListener('load', function() {
var auth0 = aid.auth0.instance;
var targetUrl = aid.toParameterByName('targetUrl') || aid.toAbsoluteUrl("/");
if (aid.doesUserLogInLocally()) {
aid.redirectTo(targetUrl);
} else {
auth0.getSSOData(onSsoDataHandlingAuthentication);
}
setTimeout(function() {
document.querySelector('.container').style.display = "inline-block";
}, 3000);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Helper function section
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function onSsoDataHandlingAuthentication(err, data) {
var hasSsoSession = !err && data && data.sso;
if (hasSsoSession)
redirectToAuth0ForSso();
else
aid.redirectTo(aid.toMidasAccountsUrl('/sso'));
function redirectToAuth0ForSso() {
auth0.signin({
connection: data.lastUsedConnection.name,
state: targetUrl,
scope: 'openid name picture roles'
});
}
}
});