-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
48 lines (43 loc) · 1 KB
/
index.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
<html>
<head>
<title>quick jwt decoder</title>
<style>
textarea{width:300px; height:60px; display:block}
</style>
<body>
<form id="form" action="parse">
<textarea name="jwt"></textarea>
<textarea name="out"></textarea>
<input type="button" onclick="decodejwt()" value="parse" />
</form>
<script type="text/javascript">
let b64DecodeUnicode = str =>
decodeURIComponent(
Array.prototype.map.call(atob(str), c =>
'%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)
).join(''))
let parseJwt = token =>
JSON.parse(
b64DecodeUnicode(
token.split('.')[1].replace('-', '+').replace('_', '/')
)
)
/*
the old way with event listener
let form = document.getElementById("form")
form.addEventListener("submit", (e) => {
form.out.value = JSON.stringify(
parseJwt(form.jwt.value)
)
e.preventDefault();
})
*/
function decodejwt() {
let form = document.getElementById("form")
form.out.value = JSON.stringify(
parseJwt(form.jwt.value)
)
}
</script>
</body>
</html>