-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresults.html
More file actions
530 lines (453 loc) · 24.3 KB
/
results.html
File metadata and controls
530 lines (453 loc) · 24.3 KB
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>OAuth2 Results - Playground</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="icon" href="favicon.ico">
<link rel="stylesheet" href="assets/css/styles.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/atom-one-light.min.css">
</head>
<body class="bg-slate-50 text-slate-700 font-mono min-h-screen flex items-center justify-center p-4">
<div class="w-full max-w-6xl mx-auto bg-white border border-slate-200 shadow-lg p-6">
<div class="border-b border-slate-200 pb-4 mb-6">
<h1 class="text-2xl font-bold text-slate-800 flex items-center">
Authentication Results
</h1>
<p class="text-slate-600 text-sm mt-1">
Token analysis and authentication details
</p>
</div>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6 h-[68vh]">
<div class="border border-slate-200 bg-white flex flex-col min-h-0">
<div class="bg-blue-50 border-b border-slate-200 p-3 flex-shrink-0">
<h2 class="text-lg font-semibold text-slate-800 flex items-center">
<span class="mr-2 text-blue-500">§</span>
Raw Tokens
</h2>
</div>
<div class="space-y-5 p-5 flex-1 overflow-y-auto">
<div>
<div id="accessTokenHeader" class="flex justify-between items-center mb-2">
<h3 class="text-sm font-semibold text-slate-700 uppercase tracking-wide">Access Token</h3>
<button id="refreshAccessTokenBtn" class="text-xs bg-amber-100 hover:bg-amber-200 text-amber-700 px-2 py-1 rounded transition-colors">
Refresh
</button>
</div>
<div id="accessTokenJWTDisplay" class="w-full px-3 py-2 bg-slate-50 border border-slate-300 text-slate-700 font-mono text-xs overflow-x-auto hidden cursor-text select-all"></div>
<textarea id="accessTokenDisplay" readonly rows="5"
class="w-full px-3 py-2 bg-slate-50 border border-slate-300 text-slate-700 font-mono text-xs focus:outline-none cursor-text select-all"
></textarea>
</div>
<div id="idTokenSection">
<div id="idTokenHeader" class="mb-2">
<h3 class="text-sm font-semibold text-slate-700 uppercase tracking-wide">ID Token</h3>
</div>
<div id="idTokenJWTDisplay" class="w-full px-3 py-2 bg-slate-50 border border-slate-300 text-slate-700 font-mono text-xs overflow-x-auto hidden cursor-text select-all"></div>
<textarea id="idTokenDisplay" readonly rows="5"
class="w-full px-3 py-2 bg-slate-50 border border-slate-300 text-slate-700 font-mono text-xs focus:outline-none cursor-text select-all"
></textarea>
</div>
<div id="refreshTokenSection">
<h3 class="text-sm font-semibold text-slate-700 mb-2 uppercase tracking-wide border-b border-slate-200 pb-1">
Refresh Token
</h3>
<textarea id="refreshTokenDisplay" readonly
class="w-full px-3 py-2 bg-slate-50 border border-slate-300 text-slate-700 font-mono text-xs focus:outline-none cursor-text select-all"
rows="2"></textarea>
</div>
<div>
<h3 class="text-sm font-semibold text-slate-700 mb-2 uppercase tracking-wide border-b border-slate-200 pb-1">
Token Metadata
</h3>
<div class="bg-slate-50 border border-slate-200 p-3 space-y-2 text-sm">
<div class="flex justify-between">
<span class="font-medium text-slate-700">Token Type:</span>
<span id="tokenTypeBearer" class="text-slate-600"></span>
</div>
<div class="flex justify-between">
<span class="font-medium text-slate-700">Scope:</span>
<span id="tokenScope" class="text-slate-600"></span>
</div>
<div class="flex justify-between">
<span class="font-medium text-slate-700">Expires In:</span>
<span id="tokenExpiresIn" class="text-slate-600"></span>
</div>
</div>
</div>
</div>
</div>
<div class="border border-slate-200 bg-white flex flex-col min-h-0">
<div class="bg-blue-50 border-b border-slate-200 p-3 flex-shrink-0">
<h2 class="text-lg font-semibold text-slate-800 flex items-center">
<span class="mr-2 text-blue-500">∞</span>
Token Analysis
</h2>
</div>
<div class="p-4 space-y-5 flex-1 overflow-y-auto">
<div id="opaqueTokenSection" class="hidden">
<h3 class="text-base font-bold text-slate-800 mb-2">Token Information</h3>
<hr><br>
<div class="bg-slate-50 border border-slate-200 p-3 space-y-2 text-sm">
<div class="text-center py-6">
<div class="text-slate-500 mb-2">X</div>
<p class="text-slate-600">This is an opaque access token</p>
<p class="text-xs text-slate-500 mt-1">Cannot decode internal structure</p>
</div>
</div>
</div>
<div id="accessTokenAnalysisSection">
<div class="flex justify-between items-center mb-2">
<h3 class="text-base font-bold text-slate-800 mb-2">Access Token Details</h3>
<button id="validateTokenBtn" class="text-xs bg-blue-100 hover:bg-blue-200 text-blue-700 px-2 py-1 rounded transition-colors">
Validate
</button>
</div>
<hr><br>
<div class="bg-slate-50 border border-slate-200 p-3 space-y-2 text-sm mb-4">
<div class="space-y-2 text-xs">
<div class="flex justify-between">
<span class="font-medium text-slate-700">Type:</span>
<span id="tokenType" class="text-green-600 font-semibold"></span>
</div>
<div id="tokenAlgorithmRow" class="flex justify-between">
<span class="font-medium text-slate-700">Algorithm:</span>
<span id="tokenAlgorithm" class="text-slate-600"></span>
</div>
<div class="flex justify-between">
<span class="font-medium text-slate-700">Valid:</span>
<span id="tokenValid" class="text-green-600"></span>
</div>
<div id="tokenExpiryRow" class="flex justify-between">
<span class="font-medium text-slate-700">Expires:</span>
<span id="tokenExpiry" class="text-slate-600"></span>
</div>
</div>
</div>
<div id="jwtHeaderSection">
<h4 class="text-sm font-semibold text-slate-700 mb-1">Header</h4>
<div class="bg-slate-50 border border-slate-200 p-3 mb-4">
<pre id="jwtHeaderDisplay" class="text-xs"><code class="language-json"></code></pre>
</div>
</div>
<div id="jwtPayloadSection">
<h4 class="text-sm font-semibold text-slate-700 mb-1">Payload</h4>
<div class="bg-slate-50 border border-slate-200 p-3 mt-4">
<pre id="jwtPayloadDisplay" class="text-xs"><code class="language-json"></code></pre>
</div>
</div>
</div>
<div id="idTokenAnalysisSection">
<h3 class="text-base font-bold text-slate-800 mb-2">ID Token Details</h3>
<hr><br>
<div id="idTokenHeaderSection">
<h4 class="text-sm font-semibold text-slate-700 mb-1">Header</h4>
<div class="bg-slate-50 border border-slate-200 p-3 mb-4">
<pre id="idTokenHeaderDisplay" class="text-xs"><code class="language-json"></code></pre>
</div>
</div>
<div id="idTokenPayloadSection">
<h4 class="text-sm font-semibold text-slate-700 mb-1">Payload</h4>
<div class="bg-slate-50 border border-slate-200 p-3">
<pre id="idTokenPayloadDisplay" class="text-xs"><code class="language-json"></code></pre>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="border-t border-slate-200 pt-4 mt-6 flex flex-wrap justify-end gap-2">
<button id="logoutBtn" class="bg-red-500 hover:bg-red-600 text-white px-3 py-1 text-sm font-semibold transition-colors rounded-sm">
Logout
</button>
<button id="restartFlowBtn" class="bg-slate-500 hover:bg-slate-600 text-white px-3 py-1 text-sm font-semibold transition-colors rounded-sm">
Start New Flow
</button>
</div>
</div>
<div id="confirmModal" class="fixed inset-0 bg-black bg-opacity-50 hidden items-center justify-center z-50">
<div class="bg-white border border-slate-300 shadow-xl max-w-md w-full mx-4">
<div class="p-6">
<div class="flex items-center mb-4">
<span class="mr-3 text-xl">⚠</span>
<h3 class="text-lg font-semibold text-slate-800">Confirm Action</h3>
</div>
<p id="modalMessage" class="text-slate-600 mb-6 font-mono">Are you sure you want to proceed?</p>
<div class="flex justify-end space-x-2">
<button id="modalCancel"
class="px-4 py-1 text-slate-600 bg-white border border-slate-300 hover:bg-slate-50 font-semibold transition-colors h-[34px]">
Cancel
</button>
<button id="modalConfirm"
class="px-4 py-1 bg-red-500 hover:bg-red-600 text-white border border-red-500 font-semibold transition-colors h-[34px]">
Confirm
</button>
</div>
</div>
</div>
</div>
<div id="notifications" class="fixed top-4 right-4 space-y-2 z-40 font-mono"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<script src="assets/js/utils.js"></script>
<script src="assets/js/ui-service.js"></script>
<script src="assets/js/storage-service.js"></script>
<script src="assets/js/oauth2-service.js"></script>
<script>
const oauth2PlaygroundData = $.parseJSON(StorageService.getFromStorage() || '{}');
const isM2MFlow = oauth2PlaygroundData.grantType === "client_credentials" || oauth2PlaygroundData.grantType === "password";
if (isM2MFlow) {
$("#logoutBtn").text("Revoke Token");
if (oauth2PlaygroundData.grantType === "client_credentials" && isM2MFlow) {
$("#refreshAccessTokenBtn").hide();
}
}
function highlightJSON(jsonObj, elementSelector) {
const jsonString = JSON.stringify(jsonObj, null, 2);
$(elementSelector).text(jsonString);
hljs.highlightElement($(elementSelector)[0]);
}
function formatBytes(bytes) {
if (bytes < 1024) {
return bytes + ' bytes';
} else {
return (bytes / 1024).toFixed(1) + ' KB';
}
}
function displayJWTWithColors(token, displayElementId, headerElementId) {
const parts = token.split('.');
if (parts.length !== 3) return;
const $display = $(`#${displayElementId}`);
$display.empty();
const header = $('<span>').text(parts[0]).addClass('text-yellow-600 break-all');
const dot1 = $('<span>').text('.').addClass('text-gray-300');
const payload = $('<span>').text(parts[1]).addClass('text-teal-600 break-all');
const dot2 = $('<span>').text('.').addClass('text-gray-300');
const signature = $('<span>').text(parts[2]).addClass('text-gray-500 break-all');
$display.append(header, dot1, payload, dot2, signature);
$display.removeClass('hidden');
if (headerElementId) {
const tokenSize = new Blob([token]).size;
const $header = $(`#${headerElementId} h3`);
// Remove existing size span if present
$header.find('.token-size').remove();
// Add new size span
const $sizeSpan = $('<span>').text(' (' + formatBytes(tokenSize) + ')').addClass('text-slate-500 font-normal text-xs ml-1 token-size');
$header.append($sizeSpan);
}
}
function decodeJWT(token) {
try {
const parts = token.split('.');
if (parts.length !== 3) {
throw new Error('Invalid JWT format');
}
const header = JSON.parse(atob(parts[0].replace(/-/g, '+').replace(/_/g, '/')));
const payload = JSON.parse(atob(parts[1].replace(/-/g, '+').replace(/_/g, '/')));
const signature = parts[2];
return { header, payload, signature };
} catch (error) {
console.error('Error decoding JWT:', error);
return null;
}
}
function formatTimestamp(timestamp) {
if (!timestamp) return 'N/A';
return new Date(timestamp * 1000).toISOString().replace('T', ' ').replace('Z', ' UTC');
}
function isTokenExpired(exp) {
if (!exp) return false;
return Date.now() >= exp * 1000;
}
function isOpaqueToken(token) {
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
return uuidRegex.test(token) || !token.includes('.');
}
function initializeTokenData() {
const tokenResponse = JSON.parse(sessionStorage.getItem("token_response"));
if (!tokenResponse) {
console.error('No token response found in session storage');
return;
}
const $accessTokenDisplay = $("#accessTokenDisplay");
$accessTokenDisplay.val(tokenResponse.access_token);
if (tokenResponse.access_token) {
const isOpaque = isOpaqueToken(tokenResponse.access_token);
if (isOpaque) {
$accessTokenDisplay.attr("rows", 1);
$("#accessTokenAnalysisSection").addClass("hidden");
$("#opaqueTokenSection").removeClass("hidden");
$("#tokenType").text("Opaque");
$("#tokenScope").text(tokenResponse.scope || 'N/A');
} else {
displayJWTWithColors(tokenResponse.access_token, 'accessTokenJWTDisplay', 'accessTokenHeader');
$accessTokenDisplay.addClass('hidden');
$("#accessTokenAnalysisSection").removeClass("hidden");
$("#opaqueTokenSection").addClass("hidden");
const accessTokenData = decodeJWT(tokenResponse.access_token);
if (accessTokenData) {
highlightJSON(accessTokenData.header, "#jwtHeaderDisplay code");
highlightJSON(accessTokenData.payload, "#jwtPayloadDisplay code");
$("#tokenType").text(accessTokenData.header.typ || 'JWT');
$("#tokenAlgorithm").text(accessTokenData.header.alg || 'Unknown');
const isExpired = isTokenExpired(accessTokenData.payload.exp);
$("#tokenValid").html(isExpired ? '<span class="text-red-600">✗ Expired</span>' : '<span class="text-green-600">✓ Valid</span>');
$("#tokenExpiry").text(formatTimestamp(accessTokenData.payload.exp));
$("#keyId").text(accessTokenData.header.kid || 'N/A');
$("#signatureStatus").html('<span class="text-green-600">✓ Verified</span>');
$("#tokenScope").text(tokenResponse.scope || accessTokenData.payload.scope || 'N/A');
} else {
$("#accessTokenAnalysisSection").addClass("hidden");
$("#opaqueTokenSection").removeClass("hidden");
}
}
}
const $refreshTokenDisplay = $("#refreshTokenDisplay");
if (tokenResponse.refresh_token) {
$refreshTokenDisplay.val(tokenResponse.refresh_token);
$("#refreshTokenSection").removeClass("hidden");
$("#refreshAccessTokenBtn").removeClass("hidden");
} else {
$("#refreshTokenSection").addClass("hidden");
$("#refreshAccessTokenBtn").addClass("hidden");
}
const $idTokenDisplay = $("#idTokenDisplay");
if (tokenResponse.id_token) {
$idTokenDisplay.val(tokenResponse.id_token);
displayJWTWithColors(tokenResponse.id_token, 'idTokenJWTDisplay', 'idTokenHeader');
$idTokenDisplay.addClass('hidden');
$("#idTokenSection").removeClass("hidden");
$("#idTokenAnalysisSection").removeClass("hidden");
const idTokenData = decodeJWT(tokenResponse.id_token);
if (idTokenData) {
highlightJSON(idTokenData.header, "#idTokenHeaderDisplay code");
highlightJSON(idTokenData.payload, "#idTokenPayloadDisplay code");
}
} else {
$("#idTokenSection").addClass("hidden");
$("#idTokenAnalysisSection").addClass("hidden");
}
$("#tokenTypeBearer").text(tokenResponse.token_type || 'Bearer');
$("#tokenExpiresIn").text((tokenResponse.expires_in || 'N/A') + ' seconds');
}
$(document).ready(function() {
initializeTokenData();
const tokenResponse = JSON.parse(sessionStorage.getItem("token_response"));
$("#refreshAccessTokenBtn").click(function() {
const cachedTokenResponse = JSON.parse(sessionStorage.getItem("token_response"));
if (cachedTokenResponse && cachedTokenResponse.refresh_token) {
console.log("Refreshing access token...");
$(this).prop('disabled', true).text('Refreshing...');
OAuth2Service.refreshToken(cachedTokenResponse.refresh_token, oauth2PlaygroundData.grantType === "authorization_code_pkce")
.then(function(response) {
console.log("Refresh token response:", response);
console.log(JSON.stringify(response));
sessionStorage.setItem("token_response", JSON.stringify(response));
initializeTokenData();
UIService.showNotification("Access token refreshed successfully!", "success");
})
.catch(function(error) {
console.error("Error refreshing token:", error);
UIService.showNotification("Failed to refresh token: " + error.message, "error");
})
.finally(() => {
$(this).prop('disabled', false).text('Refresh');
});
} else {
UIService.showNotification("No refresh token available", "error");
}
});
$("#validateTokenBtn").click(function() {
if (tokenResponse && tokenResponse.access_token) {
const tokenData = decodeJWT(tokenResponse.access_token);
if (tokenData) {
const isExpired = isTokenExpired(tokenData.payload.exp);
$.ajax({
url: oauth2PlaygroundData.discoveryUrl,
method: "GET",
success: function (data) {
const jwksUri = data.jwks_uri;
$.ajax({
url: jwksUri,
method: "GET",
success: function (jwksData) {
const keys = jwksData.keys;
const validKeyFound = keys.find(k => k.kid === tokenData.header.kid);
if (!validKeyFound) {
UIService.showNotification("Key ID not found in JWKS", "error");
}
},
error: function () {
UIService.showNotification("Failed to fetch JWKS", "error");
}
});
}
});
UIService.showNotification(`Token validation: ${isExpired ? "Not valid" : "Valid"}`, isExpired ? "error" : "success");
}
}
});
$("#logoutBtn").click(function() {
UIService.showModal(
"Are you sure you want to logout? This will clear all session data.",
() => !isM2MFlow ? OAuth2Service.logout() :
OAuth2Service.revokeToken(tokenResponse.access_token).then(() => window.location.href = "index.html")
);
});
$("#restartFlowBtn").click(function() {
sessionStorage.clear();
window.location.href = "index.html";
});
async function copyTokenToClipboard(token, tokenName) {
if (!token) {
UIService.showNotification(`No ${tokenName} available to copy`, "warning");
return;
}
try {
if (navigator.clipboard && window.isSecureContext) {
await navigator.clipboard.writeText(token);
UIService.showNotification(`${tokenName} copied to clipboard`, "success");
} else {
const textarea = document.createElement('textarea');
textarea.value = token;
document.body.appendChild(textarea);
textarea.select();
document.execCommand('copy');
document.body.removeChild(textarea);
UIService.showNotification(`${tokenName} copied to clipboard`, "success");
}
} catch (error) {
console.error('Failed to copy token:', error);
UIService.showNotification(`Failed to copy ${tokenName}`, "error");
}
}
function selectElementText(element) {
const range = document.createRange();
const selection = window.getSelection();
range.selectNodeContents(element);
selection.removeAllRanges();
selection.addRange(range);
}
$("#accessTokenDisplay, #accessTokenJWTDisplay").on('click', function() {
if (this.id === 'accessTokenJWTDisplay') {
selectElementText(this);
}
copyTokenToClipboard(tokenResponse.access_token, "Access Token");
});
$("#idTokenDisplay, #idTokenJWTDisplay").on('click', function() {
if (this.id === 'idTokenJWTDisplay') {
selectElementText(this);
}
copyTokenToClipboard(tokenResponse.id_token, "ID Token");
});
$("#refreshTokenDisplay").on('click', function() {
this.select();
this.setSelectionRange(0, 99999);
copyTokenToClipboard(tokenResponse.refresh_token, "Refresh Token");
});
});
</script>
</body>
</html>