postmanlabs/httpbin

Decode JWT in "Authentication: Bearer ..." request header

lathspell opened this issue · 0 comments

It would be nice if httpbin could decode the JWT that was passed via the "Authentication: Bearer ..." header and show it as JSON.

To avoid confusion, this is different than GET /bearer under "Auth", where one sets his own header.
It should rather be GET /bearer-token-as-json or similar under "Request Inspection".

Decoding the JWT is pretty simple, here is a shell script that I use so far:

echo "$access_token" | cut -d. -f2 | base64 -d --ignore-garbage \
    | jq 'if .iat then (.iatStr = (.iat|gmtime|strftime("%Y-%m-%dT%H:%M:%SZ"))) else . end' \
    | jq 'if .exp then (.expStr = (.exp|gmtime|strftime("%Y-%m-%dT%H:%M:%SZ"))) else . end'

(the last two lines are just a suggestion that decoding the Unix timestamp would be very convenient as well)