Skip to content

Commit 5299440

Browse files
committed
first stab at UserManager (OidcTokenManager replacement)
1 parent 92b69b4 commit 5299440

15 files changed

+1906
-215
lines changed

dist/IdentityModel.js

Lines changed: 533 additions & 41 deletions
Large diffs are not rendered by default.

sample/public/IdentityModel.js

Lines changed: 785 additions & 132 deletions
Large diffs are not rendered by default.

sample/public/index.html

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,9 @@
55
<link rel='stylesheet' href='app.css'>
66
</head>
77
<body>
8-
<div>
9-
<a href='index.html'>clear url</a>
10-
<label>follow links
11-
<input type="checkbox" id='links'>
12-
</label>
13-
<button id='signin'>signin</button>
14-
<button id='processSignin'>process signin response</button>
15-
<button id='signout'>signout</button>
16-
<button id='processSignout'>process signout response</button>
17-
</div>
18-
19-
<pre id='out'></pre>
20-
21-
<script src='IdentityModel.js'></script>
22-
<script src='app.js'></script>
8+
<ul>
9+
<li><a href='oidc-client-sample.html'>OidcClient Sample</a></li>
10+
<li><a href='user-manager-sample.html'>UserManager Sample</a></li>
11+
</ul>
2312
</body>
2413
</html>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>oidc-client test</title>
5+
<link rel='stylesheet' href='app.css'>
6+
</head>
7+
<body>
8+
<div>
9+
<a href='oidc-client-sample.html'>clear url</a>
10+
<label>follow links
11+
<input type="checkbox" id='links'>
12+
</label>
13+
<button id='signin'>signin</button>
14+
<button id='processSignin'>process signin response</button>
15+
<button id='signout'>signout</button>
16+
<button id='processSignout'>process signout response</button>
17+
</div>
18+
19+
<pre id='out'></pre>
20+
21+
<script src='IdentityModel.js'></script>
22+
<script src='oidc-client-sample.js'></script>
23+
</body>
24+
</html>
Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,64 +19,64 @@ IdentityModel.Log.logLevel = IdentityModel.Log.INFO;
1919
var settings = {
2020
authority: 'http://localhost:5000/oidc',
2121
client_id: 'js.tokenmanager',
22-
redirect_uri: 'http://localhost:5000/index.html',
23-
post_logout_redirect_uri: 'http://localhost:5000/index.html',
22+
redirect_uri: 'http://localhost:5000/oidc-client-sample.html',
23+
post_logout_redirect_uri: 'http://localhost:5000/oidc-client-sample.html',
2424
response_type: 'id_token token',
2525
scope: 'openid email roles',
26-
27-
filterProtocolClaims : true,
28-
loadUserInfo:true
26+
27+
filterProtocolClaims: true,
28+
loadUserInfo: true
2929
};
30-
var oidcClient = new IdentityModel.OidcClient(settings);
30+
var client = new IdentityModel.OidcClient(settings);
3131

3232
///////////////////////////////
3333
// functions for UI elements
3434
///////////////////////////////
3535
function signin() {
36-
oidcClient.createSigninRequest({data:{bar:15}}).then(function(req){
36+
client.createSigninRequest({ data: { bar: 15 } }).then(function(req) {
3737
log("signin request", req, "<a href='" + req.url + "'>go signin</a>");
38-
if (followLinks()){
38+
if (followLinks()) {
3939
window.location = req.url;
4040
}
41-
}, function (err) {
41+
}, function(err) {
4242
log(err);
4343
});
4444
}
4545

4646
var signinResponse;
4747
function processSigninResponse() {
48-
oidcClient.processSigninResponse().then(function(response){
48+
client.processSigninResponse().then(function(response) {
4949
signinResponse = response;
5050
log("signin response", signinResponse);
51-
}, function (err) {
51+
}, function(err) {
5252
log(err.message);
5353
});
5454
}
5555

5656
function signout() {
57-
oidcClient.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()){
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)