Skip to content

andreburgaud/jwt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON Web Token (JWT)

jwt is a command line (CLI) tool to encode or decode JSON Web Tokens (JWT).

Usage

JWT Decode Token File

jwt decode tokens/hs256.token
{
  "header": {
    "alg": "HS256",
    "typ": "JWT"
  },
  "payload": {
    "sub": "1234567890",
    "name": "John Doe",
    "iat": 1516239022
  },
  "signature": "SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
}

JWT Decode Token String

jwt decode --string eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
{
  "header": {
    "alg": "HS256",
    "typ": "JWT"
  },
  "payload": {
    "sub": "1234567890",
    "name": "John Doe",
    "iat": 1516239022
  },
  "signature": "SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
}

From stdin

cat tokens/hs256.token | jwt decode
{
  "header": {
    "alg": "HS256",
    "typ": "JWT"
  },
  "payload": {
    "sub": "1234567890",
    "name": "John Doe",
    "iat": 1516239022
  },
  "signature": "SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
}

JWT Encode JSON File

jwt encode --key secret_key tokens/hs256.json
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.-31VfEDt_2aatZ0NIjznd27ruqyeMC4zus1J3hjZlts

JWT Encode JSON String

export JWT_JSON='{"header":{"alg":"HS256","typ":"JWT"},"payload":{"sub":"1234567890","name":"John Doe","iat":1516239022},"signature":"SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"}'
jwt encode --key secret_key --string "$JWT_JSON"
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.-31VfEDt_2aatZ0NIjznd27ruqyeMC4zus1J3hjZlts

Pipe Encode and Decode

jwt encode --key secret_key tokens/hs256.json | jwt decode
{
  "header": {
    "alg": "HS256",
    "typ": "JWT"
  },
  "payload": {
    "sub": "1234567890",
    "name": "John Doe",
    "iat": "2018-01-17T19:30:22-06:00"
  },
  "signature": "-31VfEDt_2aatZ0NIjznd27ruqyeMC4zus1J3hjZlts"
}

Help

jwt --help
                                       JWT Command Line 0.11.0
                               Copyright (c) 2021-2024 - Andre Burgaud
                                             MIT License
Description:
  Manipulate (encode, or decode) JSON Web Tokens (JWT).

Usage:
  jwt [OPTIONS]
  jwt [COMMAND] [OPTIONS] [ARGS]

Options:
  -h, --help       Print help
  -v, --version    Print version info

Commands:
  decode    Decode a Base64 encoded JWT into a valid JSON string
  encode    Encode a JSON file or string into a Base64 encoded JWT

  jwt [COMMAND] --help for more information on a specific command.

Development

jwt is written in Nim, which needs to be installed to build jwt.

Debug Build

To build a debug version of jwt, execute the following command:

nimble build

The executable will be available at the root of the project. For a simple test, on Linux or Mac OS, you can run:

./jwt decode tokens/hs256.token

Release Build

To build a debug version of jwt, execute the following command:

nimble release

The executable will be available in bin/release.

Test

To execute the unit tests, execute the following command:

nimble test

Build a Windows package on Linux

to build a windows distribution on Linux:

nimble dist_xc_win64

The nimbe task dist_xc_win64 will create a 64-bit release version and a zip package under dist.

License

jwt is release under the MIT License

Resources

About

JWT Command Line tool

Topics

Resources

License

Stars

1 star

Watchers

1 watching

Forks

Packages

 
 
 

Contributors