Skip to content

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

@lathspell

Description

@lathspell

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions