Skip to content

Commit

Permalink
update to oidc-client's new check session support
Browse files Browse the repository at this point in the history
  • Loading branch information
brockallen committed Aug 12, 2016
1 parent 9cedde1 commit 5efe5ec
Show file tree
Hide file tree
Showing 6 changed files with 2,142 additions and 1,393 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@
<Content Include="app.js" />
<Content Include="bootstrap.min.css" />
<Content Include="oidc-client.js" />
<Content Include="oidc-client.min.js" />
<Content Include="silent_renew.html" />
<Content Include="check_session.html" />
<None Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon>
</None>
Expand Down
70 changes: 39 additions & 31 deletions source/Clients/JavaScriptImplicitClient/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ var settings = {
silent_redirect_uri: window.location.protocol + "//" + window.location.host + "/silent_renew.html",
automaticSilentRenew: true,

// will raise events for when user has performed a logout at IdentityServer
monitorSession : true,

// this will allow all the OIDC protocol claims to vbe visible in the window. normally a client app
// wouldn't care about them or want them taking up space
filterProtocolClaims: true,
Expand Down Expand Up @@ -65,6 +68,11 @@ mgr.events.addSilentRenewError(function (e) {
log("silent renew error", e.message);
});

mgr.events.addUserSignedOut(function () {
console.log("user signed out");
log("user signed out");
});

///////////////////////////////
// UI event handlers
///////////////////////////////
Expand Down Expand Up @@ -135,36 +143,36 @@ function callApi() {
xhr.send();
}

function checkSessionState(user) {
mgr.metadataService.getCheckSessionIframe().then(function (url) {
if (url && user && user.session_state) {
console.log("setting up check session iframe for session state", user.session_state);
document.getElementById("rp").src = "check_session.html#" +
"session_state=" + user.session_state +
"&check_session_iframe=" + url +
"&client_id=" + mgr.settings.client_id
;
}
else {
console.log("no check session url, user, or session state: not setting up check session iframe");
document.getElementById("rp").src = "about:blank";
}
});
}

window.onmessage = function (e) {
if (e.origin === window.location.protocol + "//" + window.location.host && e.data === "changed") {
console.log("user session has changed");
mgr.removeUser();
mgr.signinSilent().then(function () {
// Session state changed but we managed to silently get a new identity token, everything's fine
console.log('renewTokenSilentAsync success');
}).catch(function (err) {
// Here we couldn't get a new identity token, we have to ask the user to log in again
console.log('renewTokenSilentAsync failed', err.message);
});
}
}
//function checkSessionState(user) {
// mgr.metadataService.getCheckSessionIframe().then(function (url) {
// if (url && user && user.session_state) {
// console.log("setting up check session iframe for session state", user.session_state);
// document.getElementById("rp").src = "check_session.html#" +
// "session_state=" + user.session_state +
// "&check_session_iframe=" + url +
// "&client_id=" + mgr.settings.client_id
// ;
// }
// else {
// console.log("no check session url, user, or session state: not setting up check session iframe");
// document.getElementById("rp").src = "about:blank";
// }
// });
//}

//window.onmessage = function (e) {
// if (e.origin === window.location.protocol + "//" + window.location.host && e.data === "changed") {
// console.log("user session has changed");
// mgr.removeUser();
// mgr.signinSilent().then(function () {
// // Session state changed but we managed to silently get a new identity token, everything's fine
// console.log('renewTokenSilentAsync success');
// }).catch(function (err) {
// // Here we couldn't get a new identity token, we have to ask the user to log in again
// console.log('renewTokenSilentAsync failed', err.message);
// });
// }
//}

///////////////////////////////
// init
Expand Down Expand Up @@ -217,6 +225,7 @@ function display(selector, msg) {
document.querySelector(selector).innerHTML += msg + '\r\n';
}
}

function showUser(user) {
if (!user) {
log("user not signed in");
Expand All @@ -238,5 +247,4 @@ function showUser(user) {
logAccessToken();
}
}
checkSessionState(user);
}
61 changes: 0 additions & 61 deletions source/Clients/JavaScriptImplicitClient/check_session.html

This file was deleted.

5 changes: 1 addition & 4 deletions source/Clients/JavaScriptImplicitClient/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ <h1>JavaScript Implicit Client</h1>
</div>

<div class="row">
<ul class="list-unstyled list-inline">
</ul>
<ul class="list-unstyled list-inline"></ul>
</div>

<div class="row">
Expand Down Expand Up @@ -71,8 +70,6 @@ <h1>JavaScript Implicit Client</h1>
</div>
</div>

<iframe id="rp" style="display:none"></iframe>

<script src="oidc-client.js"></script>
<script src="app.js"></script>
</body>
Expand Down
Loading

0 comments on commit 5efe5ec

Please sign in to comment.