Created
November 14, 2024 14:52
-
-
Save alexbridge/9a18d5117bcc2fcbf3ddb0c216a38025 to your computer and use it in GitHub Desktop.
Postman / Visualize JWT Token
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { access_token } = pm.response.json(); | |
const jwtToken = JSON.parse(atob(access_token.split('.')[1])); | |
var template = ` | |
<style type="text/css"> | |
.tftable {font-size:14px;color:#333333;width:100%;border-width: 1px;border-color: #87ceeb;border-collapse: collapse;} | |
.tftable th {font-size:18px;background-color:#87ceeb;border-width: 1px;padding: 8px;border-style: solid;border-color: #87ceeb;text-align:left;} | |
.tftable tr {background-color:#ffffff;} | |
.tftable td {font-size:14px;border-width: 1px;padding: 8px;border-style: solid;border-color: #87ceeb;} | |
.tftable tr:hover {background-color:#e0ffff;} | |
</style> | |
<h4>JWT Token</h4> | |
<table class="tftable" border="1"> | |
<tr> | |
<th>Key</th> | |
<th>Value</th> | |
</tr> | |
{{#each token}} | |
<tr> | |
<td>{{key}}</td> | |
<td>{{value}}</td> | |
</tr> | |
{{/each}} | |
</table> | |
`; | |
const templateVars = { | |
token: Object.keys(jwtToken).map(key => ({ | |
key, | |
value: jwtToken[key], | |
...key === 'iat' && { | |
value: new Date(parseInt(jwtToken[key] + '000')).toLocaleString('de-DE') | |
}, | |
...key === 'exp' && { | |
value: new Date(parseInt(jwtToken[key] + '000')).toLocaleString('de-DE') | |
} | |
})) | |
}; | |
pm.visualizer.set(template, templateVars); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment