-
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathjwt-decoder.html
More file actions
320 lines (282 loc) · 15.9 KB
/
jwt-decoder.html
File metadata and controls
320 lines (282 loc) · 15.9 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/png" href="images/logo.png">
<link rel="apple-touch-icon" href="images/logo.png">
<title>JWT Decoder - Developer Toolkit | DevDunia</title>
<meta name="description" content="Decode and verify JWT tokens. Free online JWT decoder with header and payload analysis for developers.">
<script src="https://cdn.tailwindcss.com"></script>
<script src="js/common.js"></script>
<style>
body {
background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
}
</style>
</head>
<body class="h-screen lg:ml-72">
<!-- Background: Consistent Subtle Dark Gradient -->
<div class="fixed inset-0 -z-10 bg-gradient-to-br from-gray-900 via-slate-900 to-gray-900"></div>
<!-- Main Content -->
<div class="main-content">
<!-- Main Container -->
<div class="container mx-auto px-4 pt-8 pb-24 sm:px-6 lg:px-8">
<!-- Page Header -->
<div class="text-center mb-12">
<h1 class="text-3xl sm:text-4xl font-bold mb-4 tracking-tight
text-transparent bg-clip-text bg-gradient-to-r from-blue-400 to-cyan-500">
JWT Decoder
</h1>
<p class="text-lg text-gray-400 max-w-2xl mx-auto">
Decode and analyze JWT tokens. View header, payload, and signature information.
</p>
</div>
<!-- Tool Container -->
<div class="max-w-4xl mx-auto">
<div class="bg-slate-800/70 backdrop-blur-md rounded-lg shadow-lg border border-slate-700/60 p-6">
<!-- Input Section -->
<div class="mb-6">
<label for="jwt-input" class="block text-sm font-medium text-gray-300 mb-2">
JWT Token
</label>
<textarea
id="jwt-input"
rows="4"
class="w-full px-4 py-3 bg-slate-700/50 border border-slate-600 rounded-lg text-gray-200 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent resize-none font-mono text-sm"
placeholder="Enter your JWT token here (e.g., eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...)"
></textarea>
</div>
<!-- Action Buttons -->
<div class="flex flex-wrap gap-3 mb-6">
<button id="decode-btn" class="px-6 py-3 bg-blue-600 hover:bg-blue-700 text-white font-medium rounded-lg transition-colors duration-200 flex items-center space-x-2">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 11V7a4 4 0 118 0m-4 8v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2z"></path>
</svg>
<span>Decode JWT</span>
</button>
<button class="clear-btn px-6 py-3 bg-slate-600 hover:bg-slate-700 text-white font-medium rounded-lg transition-colors duration-200 flex items-center space-x-2">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"></path>
</svg>
<span>Clear All</span>
</button>
</div>
<!-- Results Section -->
<div id="results-section" class="hidden">
<!-- Token Info -->
<div class="mb-6 p-4 bg-slate-700/30 rounded-lg border border-slate-600/50">
<h3 class="text-lg font-semibold text-blue-400 mb-3">Token Information</h3>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4 text-sm">
<div>
<span class="text-gray-400">Algorithm:</span>
<span id="algorithm" class="text-white font-mono ml-2">-</span>
</div>
<div>
<span class="text-gray-400">Type:</span>
<span id="token-type" class="text-white font-mono ml-2">-</span>
</div>
<div>
<span class="text-gray-400">Expires:</span>
<span id="expires" class="text-white font-mono ml-2">-</span>
</div>
</div>
</div>
<!-- Header Section -->
<div class="mb-6">
<div class="flex items-center justify-between mb-3">
<h3 class="text-lg font-semibold text-green-400">Header</h3>
<button class="copy-btn px-3 py-1 bg-slate-600 hover:bg-slate-700 text-white text-sm rounded transition-colors duration-200 flex items-center space-x-1" data-target="header-output">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v8a2 2 0 01-2 2h-2m-6-4l2 2m0 0l2-2m-2 2V10"></path>
</svg>
<span>Copy</span>
</button>
</div>
<textarea
id="header-output"
rows="6"
class="w-full px-4 py-3 bg-slate-700/50 border border-slate-600 rounded-lg text-gray-200 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent resize-none font-mono text-sm"
readonly
></textarea>
</div>
<!-- Payload Section -->
<div class="mb-6">
<div class="flex items-center justify-between mb-3">
<h3 class="text-lg font-semibold text-purple-400">Payload</h3>
<button class="copy-btn px-3 py-1 bg-slate-600 hover:bg-slate-700 text-white text-sm rounded transition-colors duration-200 flex items-center space-x-1" data-target="payload-output">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v8a2 2 0 01-2 2h-2m-6-4l2 2m0 0l2-2m-2 2V10"></path>
</svg>
<span>Copy</span>
</button>
</div>
<textarea
id="payload-output"
rows="8"
class="w-full px-4 py-3 bg-slate-700/50 border border-slate-600 rounded-lg text-gray-200 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent resize-none font-mono text-sm"
readonly
></textarea>
</div>
<!-- Signature Section -->
<div class="mb-6">
<div class="flex items-center justify-between mb-3">
<h3 class="text-lg font-semibold text-orange-400">Signature</h3>
<button class="copy-btn px-3 py-1 bg-slate-600 hover:bg-slate-700 text-white text-sm rounded transition-colors duration-200 flex items-center space-x-1" data-target="signature-output">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v8a2 2 0 01-2 2h-2m-6-4l2 2m0 0l2-2m-2 2V10"></path>
</svg>
<span>Copy</span>
</button>
</div>
<textarea
id="signature-output"
rows="3"
class="w-full px-4 py-3 bg-slate-700/50 border border-slate-600 rounded-lg text-gray-200 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent resize-none font-mono text-sm"
readonly
></textarea>
</div>
</div>
<!-- Error Display -->
<div id="error-section" class="hidden mb-6 p-4 bg-red-900/30 border border-red-600/50 rounded-lg">
<div class="flex items-center space-x-2">
<svg class="w-5 h-5 text-red-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
<span class="text-red-400 font-medium">Error:</span>
<span id="error-message" class="text-red-300"></span>
</div>
</div>
<!-- Examples Section -->
<div class="mt-8 p-4 bg-slate-700/30 rounded-lg border border-slate-600/50">
<h3 class="text-lg font-semibold text-blue-400 mb-3">JWT Structure</h3>
<div class="text-sm text-gray-300 space-y-2">
<p>A JWT token consists of three parts separated by dots (.)</p>
<div class="bg-slate-800/50 p-3 rounded font-mono text-xs">
<span class="text-green-400">header</span>.<span class="text-purple-400">payload</span>.<span class="text-orange-400">signature</span>
</div>
<ul class="list-disc list-inside ml-4 space-y-1">
<li><strong>Header:</strong> Contains metadata about the token (algorithm, type)</li>
<li><strong>Payload:</strong> Contains the claims (user data, expiration, etc.)</li>
<li><strong>Signature:</strong> Used to verify the token hasn't been tampered with</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Footer include -->
<div id="footer"></div>
<script>
fetch("footer.html")
.then(response => response.text())
.then(data => {
document.getElementById("footer").innerHTML = data;
})
.catch(err => console.error("Failed to load footer:", err));
</script>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const jwtInput = document.getElementById('jwt-input');
const decodeBtn = document.getElementById('decode-btn');
const resultsSection = document.getElementById('results-section');
const errorSection = document.getElementById('error-section');
const errorMessage = document.getElementById('error-message');
// Decode JWT
decodeBtn.addEventListener('click', function() {
const token = jwtInput.value.trim();
if (!token) {
showError('Please enter a JWT token');
return;
}
try {
const decoded = decodeJWT(token);
displayResults(decoded);
hideError();
} catch (error) {
showError(error.message);
hideResults();
}
});
// Helper functions
function showError(message) {
errorMessage.textContent = message;
errorSection.classList.remove('hidden');
}
function hideError() {
errorSection.classList.add('hidden');
}
function showResults() {
resultsSection.classList.remove('hidden');
}
function hideResults() {
resultsSection.classList.add('hidden');
}
function displayResults(decoded) {
// Update token info
document.getElementById('algorithm').textContent = decoded.header.alg || 'Unknown';
document.getElementById('token-type').textContent = decoded.header.typ || 'JWT';
if (decoded.payload.exp) {
const expDate = new Date(decoded.payload.exp * 1000);
const now = new Date();
const isExpired = expDate < now;
document.getElementById('expires').textContent =
`${expDate.toLocaleString()} ${isExpired ? '(Expired)' : '(Valid)'}`;
} else {
document.getElementById('expires').textContent = 'No expiration';
}
// Display header
document.getElementById('header-output').value = JSON.stringify(decoded.header, null, 2);
// Display payload
document.getElementById('payload-output').value = JSON.stringify(decoded.payload, null, 2);
// Display signature
document.getElementById('signature-output').value = decoded.signature;
showResults();
}
function decodeJWT(token) {
// Remove any whitespace
token = token.trim();
// Split the token
const parts = token.split('.');
if (parts.length !== 3) {
throw new Error('Invalid JWT format. JWT must have 3 parts separated by dots.');
}
const [headerPart, payloadPart, signaturePart] = parts;
try {
// Decode header
const header = JSON.parse(atob(headerPart.replace(/-/g, '+').replace(/_/g, '/')));
// Decode payload
const payload = JSON.parse(atob(payloadPart.replace(/-/g, '+').replace(/_/g, '/')));
return {
header,
payload,
signature: signaturePart
};
} catch (error) {
throw new Error('Failed to decode JWT. Please check if the token is valid.');
}
}
// Example on page load
window.addEventListener('load', () => {
const exampleJWT = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJleHAiOjE1MTYyNDI2MjJ9.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c';
jwtInput.value = exampleJWT;
});
});
</script>
<!-- Include Final Sidebar -->
<div id="sidebar-container"></div>
<script>
// Load final_sidebar.html content
fetch('final_sidebar.html')
.then(response => response.text())
.then(html => {
document.getElementById('sidebar-container').innerHTML = html;
})
.catch(error => {
console.error('Error loading sidebar:', error);
});
</script>
</body>
</html>