-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDECODE_TOKEN.html
More file actions
145 lines (132 loc) · 4.46 KB
/
Copy pathDECODE_TOKEN.html
File metadata and controls
145 lines (132 loc) · 4.46 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
<!DOCTYPE html>
<html>
<head>
<title>JWT Token Decoder</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 50px auto;
padding: 20px;
background: #1a1a2e;
color: #eee;
}
textarea {
width: 100%;
height: 150px;
margin: 10px 0;
padding: 10px;
background: #16213e;
color: #eee;
border: 1px solid #0f3460;
border-radius: 5px;
}
button {
background: rgb(0,200,151);
color: white;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
}
button:hover {
background: rgb(0,180,135);
}
pre {
background: #16213e;
padding: 15px;
border-radius: 5px;
overflow-x: auto;
border: 1px solid #0f3460;
}
.section {
margin: 20px 0;
}
h2 {
color: rgb(0,200,151);
}
.roles {
background: #0f3460;
padding: 10px;
border-radius: 5px;
margin: 10px 0;
}
.role {
display: inline-block;
background: rgb(0,200,151);
color: white;
padding: 5px 10px;
margin: 5px;
border-radius: 3px;
}
</style>
</head>
<body>
<h1>🔐 JWT Token Decoder</h1>
<div class="section">
<h2>Instructions:</h2>
<ol>
<li>Ouvrez la console du navigateur (F12)</li>
<li>Allez dans l'onglet "Application" ou "Stockage"</li>
<li>Cliquez sur "Local Storage" → http://localhost:4201</li>
<li>Copiez la valeur de "access_token"</li>
<li>Collez-la ci-dessous et cliquez sur "Decode"</li>
</ol>
</div>
<div class="section">
<h2>Token JWT:</h2>
<textarea id="token" placeholder="Collez votre token JWT ici..."></textarea>
<button onclick="decodeToken()">Decode Token</button>
</div>
<div class="section" id="result" style="display:none;">
<h2>Résultat:</h2>
<div id="output"></div>
</div>
<script>
function decodeToken() {
const token = document.getElementById('token').value.trim();
if (!token) {
alert('Veuillez entrer un token');
return;
}
try {
// Decode JWT
const base64Url = token.split('.')[1];
const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
const jsonPayload = decodeURIComponent(atob(base64).split('').map(c => {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
const payload = JSON.parse(jsonPayload);
// Extract roles
const roles = payload.realm_access?.roles || [];
// Display result
let html = '<h3>Informations Utilisateur:</h3>';
html += '<pre>' + JSON.stringify({
username: payload.preferred_username,
email: payload.email,
given_name: payload.given_name,
family_name: payload.family_name,
sub: payload.sub
}, null, 2) + '</pre>';
html += '<h3>Rôles (realm_access.roles):</h3>';
html += '<div class="roles">';
if (roles.length > 0) {
roles.forEach(role => {
html += '<span class="role">' + role + '</span>';
});
} else {
html += '<p>Aucun rôle trouvé</p>';
}
html += '</div>';
html += '<h3>Payload Complet:</h3>';
html += '<pre>' + JSON.stringify(payload, null, 2) + '</pre>';
document.getElementById('output').innerHTML = html;
document.getElementById('result').style.display = 'block';
} catch (e) {
alert('Erreur lors du décodage du token: ' + e.message);
}
}
</script>
</body>
</html>