natep2234 commited on
Commit
05da920
·
verified ·
1 Parent(s): 85f2ebb

Upload jwt.html with huggingface_hub

Browse files
Files changed (1) hide show
  1. jwt.html +172 -102
jwt.html CHANGED
@@ -3,138 +3,208 @@
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>jwt.decode — Decode JWT tokens instantly</title>
7
  <style>
8
- *{margin:0;padding:0;box-sizing:border-box}
9
- body{background:#0d1117;color:#c9d1d9;font-family:-apple-system,'Segoe UI',monospace;min-height:100vh;padding:3rem 1rem;display:flex;flex-direction:column;align-items:center}
10
- h1{font-size:2rem;color:#f0f6fc;margin-bottom:.25rem}
11
- .sub{color:#484f58;margin-bottom:2rem}
12
- .panel{width:100%;max-width:700px}
13
- label{color:#8b949e;font-size:.85rem;display:block;margin-bottom:.35rem;margin-top:1.25rem}
14
- textarea{background:#161b22;border:1px solid #30363d;border-radius:6px;padding:.75rem 1rem;color:#f0f6fc;font-family:'Courier New',monospace;font-size:.85rem;outline:none;width:100%;min-height:100px;resize:vertical;line-height:1.5;word-break:break-all}
15
- textarea:focus{border-color:#58a6ff}
16
- .sections{display:flex;flex-direction:column;gap:1rem;margin-top:1.25rem}
17
- .section{background:#161b22;border:1px solid #30363d;border-radius:8px;padding:1.25rem;overflow-x:auto}
18
- .section h3{font-size:.85rem;margin-bottom:.75rem;text-transform:uppercase;letter-spacing:.05em}
19
- .section h3.header-title{color:#f97583}
20
- .section h3.payload-title{color:#79c0ff}
21
- .section h3.sig-title{color:#56d364}
22
- .section pre{font-family:'Courier New',monospace;font-size:.9rem;line-height:1.6;white-space:pre-wrap;word-break:break-all}
23
- .key{color:#79c0ff}
24
- .str{color:#a5d6ff}
25
- .num{color:#d2a8ff}
26
- .bool{color:#ff7b72}
27
- .expiry{margin-top:.75rem;padding:.5rem .75rem;border-radius:4px;font-size:.85rem}
28
- .expiry.valid{background:#0d2818;color:#3fb950;border:1px solid #238636}
29
- .expiry.expired{background:#2d1117;color:#f85149;border:1px solid #da3633}
30
- .error{color:#f85149;margin-top:1rem}
31
- .parts{margin-top:.5rem}
32
- .parts span{display:inline;word-break:break-all;font-family:'Courier New',monospace;font-size:.8rem}
33
- .p1{color:#f97583}
34
- .p2{color:#79c0ff}
35
- .p3{color:#56d364}
36
- .dot{color:#484f58}
37
- .footer{margin-top:3rem;color:#30363d;font-size:.75rem}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  </style>
39
  </head>
40
  <body>
41
- <h1>jwt.decode</h1>
42
- <p class="sub">Paste a token. See everything.</p>
 
 
 
 
43
 
44
- <div class="panel">
45
- <label>JWT Token</label>
46
- <textarea id="token" placeholder="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"></textarea>
 
47
 
48
- <div class="parts" id="parts"></div>
49
- <div id="output"></div>
50
- </div>
51
 
52
- <div class="footer">Built by Atreus — dev.tools collection</div>
 
 
 
 
53
 
54
- <script>
55
- document.getElementById('token').addEventListener('input', decode);
 
 
 
 
 
 
 
56
 
57
- function decode() {
58
- const raw = document.getElementById('token').value.trim();
59
- const partsEl = document.getElementById('parts');
60
- const outEl = document.getElementById('output');
 
 
 
 
 
 
 
 
 
61
 
62
- if (!raw) { partsEl.innerHTML = ''; outEl.innerHTML = ''; return; }
 
 
 
 
63
 
64
- const segments = raw.split('.');
65
- if (segments.length !== 3) {
66
- partsEl.innerHTML = '';
67
- outEl.innerHTML = '<div class="error">Not a valid JWT — expected 3 dot-separated parts (header.payload.signature)</div>';
 
 
 
 
68
  return;
69
  }
70
 
71
- // Color the parts
72
- partsEl.innerHTML = `<span class="p1">${segments[0]}</span><span class="dot">.</span><span class="p2">${segments[1]}</span><span class="dot">.</span><span class="p3">${segments[2]}</span>`;
73
 
74
  let header, payload;
75
- try {
76
- header = JSON.parse(atob(segments[0].replace(/-/g,'+').replace(/_/g,'/')));
77
- } catch(e) {
78
- outEl.innerHTML = '<div class="error">Could not decode header (invalid base64)</div>';
79
  return;
80
  }
81
- try {
82
- payload = JSON.parse(atob(segments[1].replace(/-/g,'+').replace(/_/g,'/')));
83
- } catch(e) {
84
- outEl.innerHTML = '<div class="error">Could not decode payload (invalid base64)</div>';
85
  return;
86
  }
87
 
88
- let html = '<div class="sections">';
89
 
90
  // Header
91
- html += `<div class="section"><h3 class="header-title">Header</h3><pre>${colorJson(header)}</pre></div>`;
 
 
 
 
 
92
 
93
  // Payload
94
- let payloadExtra = '';
95
- if (payload.exp) {
96
- const expDate = new Date(payload.exp * 1000);
97
- const now = new Date();
98
- const isExpired = expDate < now;
99
- const diff = Math.abs(expDate - now);
100
- const days = Math.floor(diff / 86400000);
101
- const hours = Math.floor((diff % 86400000) / 3600000);
102
- const mins = Math.floor((diff % 3600000) / 60000);
103
- let timeStr = '';
104
- if (days > 0) timeStr += days + 'd ';
105
- if (hours > 0) timeStr += hours + 'h ';
106
- timeStr += mins + 'm';
107
- payloadExtra = `<div class="expiry ${isExpired ? 'expired' : 'valid'}">${isExpired ? 'EXPIRED' : 'VALID'} — ${isExpired ? 'expired' : 'expires'} ${expDate.toLocaleString()} (${timeStr} ${isExpired ? 'ago' : 'from now'})</div>`;
 
 
 
 
 
108
  }
109
- if (payload.iat) {
110
- const iatDate = new Date(payload.iat * 1000);
111
- payloadExtra += `<div style="color:#8b949e;font-size:.8rem;margin-top:.35rem">Issued: ${iatDate.toLocaleString()}</div>`;
112
- }
113
- if (payload.nbf) {
114
- const nbfDate = new Date(payload.nbf * 1000);
115
- payloadExtra += `<div style="color:#8b949e;font-size:.8rem;margin-top:.2rem">Not before: ${nbfDate.toLocaleString()}</div>`;
116
- }
117
-
118
- html += `<div class="section"><h3 class="payload-title">Payload</h3><pre>${colorJson(payload)}</pre>${payloadExtra}</div>`;
119
 
120
  // Signature
121
- html += `<div class="section"><h3 class="sig-title">Signature</h3><pre style="color:#56d364;font-size:.8rem;word-break:break-all">${segments[2]}</pre><div style="color:#8b949e;font-size:.8rem;margin-top:.5rem">Algorithm: ${header.alg || 'unknown'} — signature verification requires the secret key</div></div>`;
 
 
 
122
 
123
- html += '</div>';
124
- outEl.innerHTML = html;
125
  }
126
-
127
- function colorJson(obj) {
128
- const str = JSON.stringify(obj, null, 2);
129
- return str.replace(/"([^"]+)":/g, '<span class="key">"$1"</span>:')
130
- .replace(/: "([^"]*)"(,?)/g, ': <span class="str">"$1"</span>$2')
131
- .replace(/: (\d+)(,?)/g, ': <span class="num">$1</span>$2')
132
- .replace(/: (true|false)(,?)/g, ': <span class="bool">$1</span>$2')
133
- .replace(/: (null)(,?)/g, ': <span class="bool">$1</span>$2');
134
- }
135
-
136
- // Auto-decode if pasted
137
- decode();
138
  </script>
139
  </body>
140
  </html>
 
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>JWT Decoder — dev.tools</title>
7
  <style>
8
+ * { margin: 0; padding: 0; box-sizing: border-box; }
9
+ body {
10
+ background: #0a0a0a;
11
+ color: #c8c0b0;
12
+ font-family: 'Courier New', Courier, monospace;
13
+ min-height: 100vh;
14
+ padding: 2rem;
15
+ line-height: 1.6;
16
+ }
17
+ h1 {
18
+ font-size: 1.8rem;
19
+ color: #d4a54a;
20
+ margin-bottom: 0.3rem;
21
+ }
22
+ .subtitle {
23
+ color: #665e50;
24
+ font-size: 0.85rem;
25
+ margin-bottom: 2rem;
26
+ }
27
+ textarea {
28
+ width: 100%;
29
+ min-height: 120px;
30
+ background: #141414;
31
+ color: #c8c0b0;
32
+ border: 1px solid #2a2520;
33
+ border-radius: 4px;
34
+ padding: 1rem;
35
+ font-family: 'Courier New', Courier, monospace;
36
+ font-size: 0.9rem;
37
+ resize: vertical;
38
+ outline: none;
39
+ }
40
+ textarea:focus { border-color: #d4a54a; }
41
+ textarea::placeholder { color: #44403a; }
42
+ .output { margin-top: 1.5rem; }
43
+ .section {
44
+ background: #141414;
45
+ border: 1px solid #2a2520;
46
+ border-radius: 4px;
47
+ padding: 1rem;
48
+ margin-bottom: 1rem;
49
+ }
50
+ .section-title {
51
+ color: #d4a54a;
52
+ font-size: 0.8rem;
53
+ text-transform: uppercase;
54
+ letter-spacing: 0.1em;
55
+ margin-bottom: 0.8rem;
56
+ }
57
+ .field { margin-bottom: 0.5rem; }
58
+ .field-key { color: #7a9cc6; }
59
+ .field-value { color: #c8c0b0; }
60
+ .field-string { color: #a3be8c; }
61
+ .field-number { color: #d08770; }
62
+ .field-bool { color: #b48ead; }
63
+ .error {
64
+ color: #bf616a;
65
+ background: #1a1210;
66
+ border: 1px solid #3a1a1a;
67
+ border-radius: 4px;
68
+ padding: 1rem;
69
+ margin-top: 1.5rem;
70
+ }
71
+ .expiry-valid { color: #a3be8c; }
72
+ .expiry-expired { color: #bf616a; }
73
+ .sig-note {
74
+ color: #44403a;
75
+ font-size: 0.8rem;
76
+ font-style: italic;
77
+ margin-top: 0.5rem;
78
+ }
79
+ .token-parts { margin-top: 1rem; margin-bottom: 1.5rem; }
80
+ .token-parts span { word-break: break-all; }
81
+ .part-header { color: #bf616a; }
82
+ .part-payload { color: #b48ead; }
83
+ .part-sig { color: #7a9cc6; }
84
+ .dot { color: #665e50; }
85
+ .brand {
86
+ text-align: center;
87
+ color: #2a2520;
88
+ font-size: 0.75rem;
89
+ margin-top: 3rem;
90
+ }
91
  </style>
92
  </head>
93
  <body>
94
+ <h1>JWT Decoder</h1>
95
+ <p class="subtitle">Paste a token. See what's inside.</p>
96
+ <textarea id="input" placeholder="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c" spellcheck="false"></textarea>
97
+ <div id="tokenParts" class="token-parts"></div>
98
+ <div id="output" class="output"></div>
99
+ <div class="brand">dev.tools by Atreus & Loki</div>
100
 
101
+ <script>
102
+ const input = document.getElementById('input');
103
+ const output = document.getElementById('output');
104
+ const tokenParts = document.getElementById('tokenParts');
105
 
106
+ input.addEventListener('input', decode);
 
 
107
 
108
+ function b64decode(str) {
109
+ str = str.replace(/-/g, '+').replace(/_/g, '/');
110
+ while (str.length % 4) str += '=';
111
+ return JSON.parse(atob(str));
112
+ }
113
 
114
+ function formatValue(v) {
115
+ if (typeof v === 'string') return `<span class="field-string">"${escHtml(v)}"</span>`;
116
+ if (typeof v === 'number') return `<span class="field-number">${v}</span>`;
117
+ if (typeof v === 'boolean') return `<span class="field-bool">${v}</span>`;
118
+ if (v === null) return `<span class="field-bool">null</span>`;
119
+ if (Array.isArray(v)) return `<span class="field-string">[${v.map(i => typeof i === 'string' ? `"${escHtml(i)}"` : i).join(', ')}]</span>`;
120
+ if (typeof v === 'object') return `<span class="field-string">${escHtml(JSON.stringify(v))}</span>`;
121
+ return escHtml(String(v));
122
+ }
123
 
124
+ function escHtml(s) {
125
+ return s.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
126
+ }
127
+
128
+ function timeAgo(ts) {
129
+ const now = Math.floor(Date.now() / 1000);
130
+ const diff = ts - now;
131
+ const abs = Math.abs(diff);
132
+ if (abs < 60) return diff > 0 ? `in ${abs}s` : `${abs}s ago`;
133
+ if (abs < 3600) return diff > 0 ? `in ${Math.floor(abs/60)}m` : `${Math.floor(abs/60)}m ago`;
134
+ if (abs < 86400) return diff > 0 ? `in ${Math.floor(abs/3600)}h` : `${Math.floor(abs/3600)}h ago`;
135
+ return diff > 0 ? `in ${Math.floor(abs/86400)}d` : `${Math.floor(abs/86400)}d ago`;
136
+ }
137
 
138
+ const knownClaims = {
139
+ iss: 'Issuer', sub: 'Subject', aud: 'Audience', exp: 'Expiration',
140
+ nbf: 'Not Before', iat: 'Issued At', jti: 'JWT ID',
141
+ alg: 'Algorithm', typ: 'Type', kid: 'Key ID'
142
+ };
143
 
144
+ function decode() {
145
+ const token = input.value.trim();
146
+ if (!token) { output.innerHTML = ''; tokenParts.innerHTML = ''; return; }
147
+
148
+ const parts = token.split('.');
149
+ if (parts.length !== 3) {
150
+ output.innerHTML = `<div class="error">Not a valid JWT — expected 3 parts separated by dots, got ${parts.length}.</div>`;
151
+ tokenParts.innerHTML = '';
152
  return;
153
  }
154
 
155
+ tokenParts.innerHTML = `<span class="part-header">${escHtml(parts[0])}</span><span class="dot">.</span><span class="part-payload">${escHtml(parts[1])}</span><span class="dot">.</span><span class="part-sig">${escHtml(parts[2])}</span>`;
 
156
 
157
  let header, payload;
158
+ try { header = b64decode(parts[0]); } catch(e) {
159
+ output.innerHTML = `<div class="error">Failed to decode header: ${escHtml(e.message)}</div>`;
 
 
160
  return;
161
  }
162
+ try { payload = b64decode(parts[1]); } catch(e) {
163
+ output.innerHTML = `<div class="error">Failed to decode payload: ${escHtml(e.message)}</div>`;
 
 
164
  return;
165
  }
166
 
167
+ let html = '';
168
 
169
  // Header
170
+ html += `<div class="section"><div class="section-title">Header</div>`;
171
+ for (const [k, v] of Object.entries(header)) {
172
+ const label = knownClaims[k] ? ` <span style="color:#44403a">// ${knownClaims[k]}</span>` : '';
173
+ html += `<div class="field"><span class="field-key">${escHtml(k)}</span>: ${formatValue(v)}${label}</div>`;
174
+ }
175
+ html += `</div>`;
176
 
177
  // Payload
178
+ html += `<div class="section"><div class="section-title">Payload</div>`;
179
+ for (const [k, v] of Object.entries(payload)) {
180
+ let extra = '';
181
+ const label = knownClaims[k] ? ` <span style="color:#44403a">// ${knownClaims[k]}</span>` : '';
182
+ if ((k === 'exp' || k === 'iat' || k === 'nbf') && typeof v === 'number') {
183
+ const date = new Date(v * 1000);
184
+ const ago = timeAgo(v);
185
+ const isExp = k === 'exp';
186
+ const expired = isExp && v < Math.floor(Date.now()/1000);
187
+ extra = ` <span style="color:#44403a">→ ${date.toISOString()}</span>`;
188
+ if (isExp) {
189
+ extra += expired
190
+ ? ` <span class="expiry-expired">(EXPIRED ${ago})</span>`
191
+ : ` <span class="expiry-valid">(valid, expires ${ago})</span>`;
192
+ } else {
193
+ extra += ` <span style="color:#44403a">(${ago})</span>`;
194
+ }
195
+ }
196
+ html += `<div class="field"><span class="field-key">${escHtml(k)}</span>: ${formatValue(v)}${label}${extra}</div>`;
197
  }
198
+ html += `</div>`;
 
 
 
 
 
 
 
 
 
199
 
200
  // Signature
201
+ html += `<div class="section"><div class="section-title">Signature</div>`;
202
+ html += `<div style="color:#7a9cc6;word-break:break-all;font-size:0.85rem">${escHtml(parts[2])}</div>`;
203
+ html += `<div class="sig-note">Signature cannot be verified client-side without the secret/public key.</div>`;
204
+ html += `</div>`;
205
 
206
+ output.innerHTML = html;
 
207
  }
 
 
 
 
 
 
 
 
 
 
 
 
208
  </script>
209
  </body>
210
  </html>