Skip to content
59-
if (followLinks()){
57+
client.createSignoutRequest({ id_token_hint: signinResponse && signinResponse.id_token, data: { foo: 5 } }).then(function(req) {
58+
log("signout request", req, "<a href='" + req.url + "'>go signout</a>");
59+
if (followLinks()) {
6060
window.location = req.url;
6161
}
6262
});
6363
}
6464

6565
function processSignoutResponse() {
66-
oidcClient.processSignoutResponse().then(function(response){
66+
client.processSignoutResponse().then(function(response) {
6767
signinResponse = null;
6868
log("signout response", response);
69-
}, function (err) {
69+
}, function(err) {
7070
log(err.message);
7171
});
7272
}
7373

74-
function toggleLinks(){
74+
function toggleLinks() {
7575
var val = document.getElementById('links').checked;
7676
localStorage.setItem("follow", val);
77-
77+
7878
var display = val ? 'none' : '';
79-
79+
8080
document.getElementById('processSignin').style.display = display;
8181
document.getElementById('processSignout').style.display = display;
8282
}
@@ -87,31 +87,30 @@ function followLinks() {
8787

8888
var follow = followLinks();
8989
var display = follow ? 'none' : '';
90-
document.getElementById('links').checked = follow;
90+
document.getElementById('links').checked = follow;
9191
document.getElementById('processSignin').style.display = display;
9292
document.getElementById('processSignout').style.display = display;
9393

94-
if (followLinks()){
95-
if (window.location.href.indexOf("#") >= 0){
94+
if (followLinks()) {
95+
if (window.location.href.indexOf("#") >= 0) {
9696
processSigninResponse();
9797
}
98-
else if (window.location.href.indexOf("?") >= 0){
98+
else if (window.location.href.indexOf("?") >= 0) {
9999
processSignoutResponse();
100100
}
101101
}
102102

103103
///////////////////////////////
104104
// debugging helpers
105105
///////////////////////////////
106-
107106
function log() {
108107
document.getElementById('out').innerText = '';
109108

110-
Array.prototype.forEach.call(arguments, function(msg){
109+
Array.prototype.forEach.call(arguments, function(msg) {
111110
if (typeof msg !== 'string') {
112111
msg = JSON.stringify(msg, null, 2);
113112
}
114113
document.getElementById('out').innerHTML += msg + '\r\n';
115-
114+
116115
});
117116
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>user-manager test</title>
5+
<link rel='stylesheet' href='app.css'>
6+
</head>
7+
<body>
8+
<div>
9+
<a href='user-manager-sample.html'>clear url</a>
10+
<button id='clearState'>clear stale state</button>
11+
<button id='getUser'>get user</button>
12+
<button id='startSigninMainWindow'>start signin main window</button>
13+
<button id='endSigninMainWindow'>end signin main window</button>
14+
<button id='signoutMainWindow'>start signout main window</button>
15+
</div>
16+
17+
<pre id='out'></pre>
18+
19+
<script src='IdentityModel.js'></script>
20+
<script src='user-manager-sample.js'></script>
21+
</body>
22+
</html>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
4+
///////////////////////////////
5+
// UI event handlers
6+
///////////////////////////////
7+
document.getElementById('clearState').addEventListener("click", clearState, false);
8+
document.getElementById('getUser').addEventListener("click", getUser, false);
9+
document.getElementById('startSigninMainWindow').addEventListener("click", startSigninMainWindow, false);
10+
document.getElementById('endSigninMainWindow').addEventListener("click", endSigninMainWindow, false);
11+
document.getElementById('signoutMainWindow').addEventListener("click", signoutMainWindow, false);
12+
13+
///////////////////////////////
14+
// config
15+
///////////////////////////////
16+
IdentityModel.Log.logger = console;
17+
IdentityModel.Log.logLevel = IdentityModel.Log.INFO;
18+
19+
var settings = {
20+
authority: 'http://localhost:5000/oidc',
21+
client_id: 'js.tokenmanager',
22+
redirect_uri: 'http://localhost:5000/user-manager-sample.html',
23+
post_logout_redirect_uri: 'http://localhost:5000/user-manager-sample.html',
24+
response_type: 'id_token token',
25+
scope: 'openid email roles',
26+
27+
filterProtocolClaims: true,
28+
loadUserInfo: true
29+
};
30+
var mgr = new IdentityModel.UserManager(settings);
31+
32+
///////////////////////////////
33+
// functions for UI elements
34+
///////////////////////////////
35+
function clearState(){
36+
mgr.clearStaleState().then(function(){
37+
log("clearStateState success");
38+
}, function(e){
39+
log("clearStateState error", e.message);
40+
});
41+
}
42+
43+
function getUser() {
44+
mgr.getUser(null).then(function(user) {
45+
log("got user", user);
46+
}, function(err) {
47+
log(err);
48+
});
49+
}
50+
51+
function startSigninMainWindow() {
52+
mgr.signinStartRedirect().then(function() {
53+
log("signinRedirect done");
54+
}, function(err) {
55+
log(err);
56+
});
57+
}
58+
59+
function endSigninMainWindow() {
60+
mgr.signinCompleteRedirect().then(function(user) {
61+
log("signed in", user);
62+
}, function(err) {
63+
log(err);
64+
});
65+
}
66+
67+
function signoutMainWindow() {
68+
mgr.signout().then(function() {
69+
log("signed out");
70+
}, function(err) {
71+
log(err);
72+
});
73+
}
74+
75+
///////////////////////////////
76+
// debugging helpers
77+
///////////////////////////////
78+
function log() {
79+
document.getElementById('out').innerText = '';
80+
81+
Array.prototype.forEach.call(arguments, function(msg) {
82+
if (typeof msg !== 'string') {
83+
msg = JSON.stringify(msg, null, 2);
84+
}
85+
document.getElementById('out').innerHTML += msg + '\r\n';
86+
87+
});
88+
}

‎src/IFrameNavigator.js‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
4+
import Log from './Log';
5+
6+
export default class IFrameNavigator {
7+
8+
navigate(url) {
9+
return Promise.resolve({url:url});
10+
}
11+
12+
get url(){
13+
return window.location.href;
14+
}
15+
}

‎src/PopupNavigator.js‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
4+
import Log from './Log';
5+
6+
export default class PopupNavigator {
7+
8+
navigate(url) {
9+
return Promise.resolve({url:url});
10+
}
11+
12+
get url(){
13+
return window.location.href;
14+
}
15+
}

‎src/RedirectNavigator.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
4+
import Log from './Log';
5+
6+
export default class RedirectNavigator {
7+
8+
navigate(url) {
9+
Log.info("RedirectNavigator.navigate");
10+
window.location = url;
11+
}
12+
13+
get url(){
14+
return window.location.href;
15+
}
16+
}

0 commit comments

Comments
 (0)