Skip to content

Commit 9c6867e

Browse files
committed
node sample client
1 parent 730d418 commit 9c6867e

8 files changed

Lines changed: 2587 additions & 0 deletions

File tree

‎sample/node/bower.json‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "oidc-client-node-sample",
3+
"description": "",
4+
"main": "server.js",
5+
"authors": [
6+
"Brock Allen <brockallen@gmail.com>"
7+
],
8+
"license": "ISC",
9+
"moduleType": [],
10+
"homepage": "",
11+
"ignore": [
12+
"**/.*",
13+
"node_modules",
14+
"bower_components",
15+
"test",
16+
"tests"
17+
],
18+
"dependencies": {
19+
"kjur-jsrsasign": "jsrsasign#^5.0.7"
20+
}
21+
}

‎sample/node/package.json‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "oidc-client-node-sample",
3+
"version": "1.0.0",
4+
"main": "server.js",
5+
"scripts": {
6+
"test": "echo \"Error: no test specified\" && exit 1",
7+
"start": "node server.js"
8+
},
9+
"author": "",
10+
"license": "ISC",
11+
"dependencies": {
12+
"express": "^4.13.4"
13+
},
14+
"devDependencies": {
15+
"bower": "^1.7.7"
16+
},
17+
"description": ""
18+
}

‎sample/node/public/app.css‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pre {
2+
padding:10px;
3+
background-color: lightgray;
4+
}

‎sample/node/public/app.js‎

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
///////////////////////////////
2+
// UI event handlers
3+
///////////////////////////////
4+
document.getElementById('signin').addEventListener("click", signin, false);
5+
document.getElementById('processSignin').addEventListener("click", processSigninResponse, false);
6+
document.getElementById('signout').addEventListener("click", signout, false);
7+
document.getElementById('processSignout').addEventListener("click", processSignoutResponse, false);
8+
9+
///////////////////////////////
10+
// OidcClient config
11+
///////////////////////////////
12+
OidcClient.logger = console;
13+
OidcClient.logLevel = 'INFO';
14+
15+
var settings = {
16+
authority: 'https://localhost:44333/core',
17+
client_id: 'js.manual',
18+
redirect_uri: 'http://localhost:37046/index.html',
19+
post_logout_redirect_uri: 'http://localhost:37046/index.html',
20+
response_type: 'id_token token',
21+
scope: 'openid email roles',
22+
23+
filterProtocolClaims : true,
24+
loadUserInfo:true
25+
};
26+
var oidcClient = new OidcClient(settings);
27+
28+
///////////////////////////////
29+
// functions for UI elements
30+
///////////////////////////////
31+
function signin() {
32+
oidcClient.createSigninRequest({data:{bar:15}}).then(function(req){
33+
log(req);
34+
window.location = req.url;
35+
}, function (err) {
36+
log(err);
37+
});
38+
}
39+
40+
var signinResponse;
41+
function processSigninResponse() {
42+
oidcClient.processSigninResponse().then(function(response){
43+
signinResponse = response;
44+
log(signinResponse);
45+
}, function (err) {
46+
log(err.message);
47+
});
48+
}
49+
50+
function signout() {
51+
oidcClient.createSignoutRequest({id_token_hint:signinResponse && signinResponse.id_token, data:{foo:5}}).then(function(req){
52+
window.location = req.url;
53+
//log(req);
54+
});
55+
}
56+
57+
function processSignoutResponse() {
58+
oidcClient.processSignoutResponse().then(function(response){
59+
signinResponse = null;
60+
log(response);
61+
}, function (err) {
62+
log(err.message);
63+
});
64+
}
65+
66+
67+
///////////////////////////////
68+
// debugging helpers
69+
///////////////////////////////
70+
71+
function log() {
72+
document.getElementById('out').innerText = '';
73+
74+
Array.prototype.forEach.call(arguments, function(msg){
75+
if (typeof msg !== 'string') {
76+
msg = JSON.stringify(msg, null, 2);
77+
}
78+
document.getElementById('out').innerText += msg + '\r\n';
79+
80+
});
81+
}

‎sample/node/public/index.html‎

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>oidc-client test</title>
5+
<link rel='stylesheet' href='app.css'>
6+
</head>
7+
<body>
8+
<div>
9+
<a href='index.html'>clear url</a>
10+
<button id='signin'>signin</button>
11+
<button id='processSignin'>process signin response</button>
12+
<button id='signout'>signout</button>
13+
<button id='processSignout'>process signout response</button>
14+
</div>
15+
16+
<pre id='out'></pre>
17+
18+
<script src='jsrsasign-5.0.7-all-min.js'></script>
19+
<script src='oidc-client.js'></script>
20+
<script src='app.js'></script>
21+
</body>
22+
</html>

‎sample/node/public/jsrsasign-5.0.7-all-min.js‎

Lines changed: 289 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)