Upload jwt.html with huggingface_hub
Browse files
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>
|
| 7 |
<style>
|
| 8 |
-
*{margin:0;padding:0;box-sizing:border-box}
|
| 9 |
-
body
|
| 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 |
</style>
|
| 39 |
</head>
|
| 40 |
<body>
|
| 41 |
-
<h1>
|
| 42 |
-
<p class="
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
<
|
| 45 |
-
|
| 46 |
-
|
|
|
|
| 47 |
|
| 48 |
-
|
| 49 |
-
<div id="output"></div>
|
| 50 |
-
</div>
|
| 51 |
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
-
function
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
return;
|
| 69 |
}
|
| 70 |
|
| 71 |
-
//
|
| 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 |
-
|
| 77 |
-
} catch(e) {
|
| 78 |
-
outEl.innerHTML = '<div class="error">Could not decode header (invalid base64)</div>';
|
| 79 |
return;
|
| 80 |
}
|
| 81 |
-
try {
|
| 82 |
-
|
| 83 |
-
} catch(e) {
|
| 84 |
-
outEl.innerHTML = '<div class="error">Could not decode payload (invalid base64)</div>';
|
| 85 |
return;
|
| 86 |
}
|
| 87 |
|
| 88 |
-
let html = '
|
| 89 |
|
| 90 |
// Header
|
| 91 |
-
html += `<div class="section"><
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
// Payload
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
const
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
}
|
| 109 |
-
|
| 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"><
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
-
|
| 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,'&').replace(/</g,'<').replace(/>/g,'>');
|
| 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>
|