This repository has been archived by the owner on Dec 5, 2017. It is now read-only.
forked from WrenSecurity/wrensec-sample-openid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cb-basic.html
225 lines (197 loc) · 8.97 KB
/
cb-basic.html
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
! MPL 2.0 HEADER START
!
! This Source Code Form is subject to the terms of the Mozilla Public
! License, v. 2.0. If a copy of the MPL was not distributed with this
! file, You can obtain one at http://mozilla.org/MPL/2.0/.
!
! If applicable, add the following below this MPL 2.0 HEADER, replacing
! the fields enclosed by brackets "[]" replaced with your own identifying
! information:
! Portions Copyright [yyyy] [name of copyright owner]
!
! MPL 2.0 HEADER END
!
! Copyright 2013-2015 ForgeRock AS.
!
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>OpenID Connect Basic Client Profile Response Page</title>
<link rel="shortcut icon" href="http://forgerock.com/favicon.ico">
<link type="text/css" rel="stylesheet" href="style.css">
<script type="text/javascript"
src="///code.jquery.com/jquery-latest.min.js"></script>
<!-- Used by validateSignature() -->
<script type="text/javascript"
src="///crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/hmac-sha256.js"></script>
<script type="text/javascript"
src="///crypto-js.googlecode.com/svn/tags/3.1.2/build/components/enc-base64-min.js"></script>
<script type="text/javascript" src="common.js"></script>
<script type="text/javascript" src="basic.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var code = getParameterByName("code");
var state = getParameterByName("state");
if (code != "" && state != "") {
$("#code").html("<h3>Authorization Code</h3>"
+ "<p><code>" + code + "</code></p>");
} else {
var error = parseQueryString();
$("#info").html(
"<h3>Authorization Code Response</h3>"
+ "<pre>"
+ JSON.stringify(error, undefined, 2)
+ "</pre>"
);
return;
}
// Use authorization code to retrieve access token & id_token.
$.ajax({
url: server + openam + access,
type: "POST",
beforeSend: function (xhr) {
xhr.setRequestHeader("Authorization",
authHeader(client_id, client_secret));
},
data: {
"grant_type": "authorization_code",
"code": code,
"realm": client_realm,
"redirect_uri": redirect_uri
},
accepts: "json"
}).done(function (data) {
$("#token").html(
"<h3>Token Response</h3>"
+ "<pre>"
+ JSON.stringify(data, undefined, 2)
+ "</pre>"
);
var idToken = data.id_token;
idToken = idToken.split(/\./);
var header = JSON.parse(atob(idToken[0]));
$("#header").html("<h3>Decoded ID Token Header</h3>"
+ "<pre>"
+ JSON.stringify(header, undefined, 2)
+ "</pre>"
);
var payload = JSON.parse(atob(idToken[1]));
$("#decoded").html("<h3>Decoded ID Token Content</h3>"
+ "<pre>"
+ JSON.stringify(payload, undefined, 2)
+ "</pre>"
);
var signature = idToken[2];
$("#signature").html("<h3>ID Token Signature</h3>"
+ "<pre>"
+ signature
+ "</pre>"
);
// Validate signature.
var isValid = validateSignature(idToken[0], idToken[1], signature);
if (!isValid) {
$("#info").html("Invalid id_token signature");
return;
}
// Validate id_token.
// In 12, issuer path is /openam. In 13, issuer path is /openam/oauth2.
if (payload.iss.lastIndexOf(server + openam, 0) !== 0) { // ~ startsWith
$("#info").html("Invalid id_token issuer: "
+ payload.iss);
return;
}
if (
(
payload.aud instanceof Array
&& payload.aud.indexOf(client_id) == -1
)
|| (payload.aud != client_id)) {
$("#info").html("Invalid id_token audience: "
+ payload.aud);
return;
}
if (payload.aud instanceof Array
&& payload.azp != client_id) {
$("#info").html(
"Invalid id_token authorized party: "
+ payload.azp);
return;
}
var now = new Date().getTime() / 1000;
if (now >= payload.exp) {
$("#info").html("The id_token has expired.");
return;
}
if (now < payload.iat) {
$("#info").html("The id_token was issued in the future.");
return;
}
// acr (Authentication Context Class Reference) not requested
// max_age not requested
// Use the access token to get user information.
var access_token = data.access_token.toString();
$.ajax({
url: server + openam + info,
beforeSend: function (xhr) {
xhr.setRequestHeader("Authorization",
"Bearer " + access_token);
}
}).done(function (data) {
$("#info").html(
"<h3>End User Info</h3>"
+ "<pre>"
+ JSON.stringify(
data, undefined, 2)
+ "</pre>"
);
}).fail(function (data) {
$("#info").html(
"<p>Error obtaining user info:</p>"
+ "<pre>"
+ JSON.stringify(
data, undefined, 2)
+ "</pre>"
);
});
}).fail(function (data) {
$("#info").html(
"<p>Error obtaining access token:</p>"
+ "<pre>"
+ JSON.stringify(data, undefined, 2)
+ "</pre>"
);
});
});
</script>
</head>
<body>
<div>
<a href="http://openam.forgerock.org/">
<img src="forgerock-logo.svg" width="131" height="83" align="right" alt="ForgeRock Logo">
</a>
</div>
<h3>Basic Client Profile Response Page</h3>
<p>
Concerning signature validation, see <a href="common.js">common.js</a>.
</p>
<hr>
<div id="code"><!-- code goes here --></div>
<div id="token"><!-- token goes here --></div>
<div id="header"><!-- decoded id_token header goes here --></div>
<div id="decoded"><!-- decoded id_token goes here --></div>
<div id="signature"><!-- id_token signature goes here --></div>
<div id="info"><!-- info goes here --></div>
<div>
<hr>
<p align="center">
<a href="basic.html">Try basic profile again</a> |
<a href="implicit.html">Try implicit profile</a> |
<a href="index.html">Start over</a>
</p>
</div>
</body>
</html>