Skip to content

JWT CLI and apps for encoding, decoding & working with JWT tokens

License

Notifications You must be signed in to change notification settings

peteretelej/jwt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jwt CLI

Go Report Card license GitHub release

A JWT CLI written in Go.

Also includes:

Installation

Download executable for your OS from Releases

  • Works on most platforms: Windows, iOS, Linux etc

Alternative installation (with Go):

go get -u github.com/peteretelej/jwt

Usage

Decode token and print details in human readable format

  • Add headers to sections
  • Parse timestamps
  • Provide human readable durations eg ( expires in 1yr )
./jwt TOKEN

Verify if token is signed by a secret

./jwt --secret SECRET TOKEN 

Generate JWT token

./jwt --secret demopass --sign '{"user": "John Doe"}' 

Specify an expiry period for the generated token

./jwt  --secret demopass --exp 1y --sign '{"user": "John Doe"}'
  • Supports durations (eg year to second) such as yr, mo, w, d, h,m,s
  • examples: --exp 6mo (6 months), --exp 2w (2 weeks)

Tips

If you don't want to paste secret as plain text in command line:

  • do not specify the --secret argument, it will prompt pasting or typing secret (does not print the secret)
./jwt --sign '{"user": "Jane Doe"}'
Please enter a secret to sign the JWT (and press Enter)
Usage Examples

Generating a signed JWT token

./jwt --sign '{"name": "John Doe"}' --secret demopass --exp 2w

image

Decode JWT token

./jwt eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2Mjc3NTkyNzUsIm5hbWUiOiJKb2huIERvZSJ9.SF2XbD6QpxxcV95Oa_AC1oXysfWcF9gmyMEaNAHagP0

image

Verifying a token's signing key

./jwt --secret demopass eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2Mjc3NTkyNzUsIm5hbWUiOiJKb2huIERvZSJ9.SF2XbD6QpxxcV95Oa_AC1oXysfWcF9gmyMEaNAHagP0

image

Decoding a token with multiple standard claims

./jwt eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNjIxMjY5Mjg2LCJleHAiOjE2Mzk3NTg4ODYsIm5iZiI6MTYyMzk0NzY4Nn0.GR5pGSiJZk3Ls0A429K3HIZfsmQqGnyIhPusDT5F5BU

image

License: MIT