Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jwt-generate

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jwt-generate

Generate a 'JSON Web Token' (JWT).

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

jwt-generate

Codacy Badge codebeat badge dependencies Status

Generate a JSON Web Token - JWT

Table of Contents

CLI

npm install -g jwt-generate

Commands

jwt-generate <command>

Commands:
  jwt-generate generate      Generates a JWT.
  jwt-generate decode <jwt>  Decodes a JWT.

Options:
  --version  Show version number                         [boolean]
  --help     Show help                                   [boolean]
Generate
jwt-generate generate

Generates a JWT. Either 'secret' or 'secretFile' must be supplied.

Options:
  --version         Show version number                                 [boolean]
  --help            Show help                                           [boolean]
  --secret, -s      JWT secret string.
  --secretFile, -f  File path containing the JWT Secret.
  --algorithm, -a   Choices: "RS256", "HS256".                          [string] [default: "HS256"]
  --expire, --exp   How long in seconds until the JWT should expire.    [number]
  --claims          JWT claims.
Decode
jwt-generate decode <jwt>

Decodes a JWT.

Options:
  --version  Show version number                         [boolean]
  --help     Show help                                   [boolean]

CLI Examples

Generates a JWT signed with the secret 'my-secret' using the HS256 algorithm.

jwt-generate generate --secret my-secret

{
  "headers": {
    "Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1MjAwMjYzOTIsImV4cCI6MTUyMDAyOTk5Mn0.5TkR3nHlPA2LJhe8jGxE26AnkeCkfFeVrJN5FdOUPew"
  },
  "jwt": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1MjAwMjYzOTIsImV4cCI6MTUyMDAyOTk5Mn0.5TkR3nHlPA2LJhe8jGxE26AnkeCkfFeVrJN5FdOUPew"
}

Generates a JWT signed with private key file 'private_key.pem' using the HS256 algorithm.

jwt-generate generate --secretFile private_key.pem

{
  "headers": {
    "Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1MjAwMjYzODAsImV4cCI6MTUyMDAyOTk4MH0.19sUG-ncAycxdosaZJDGpkeSfuugmEH_fCPRJtTsOI4"
  },
  "jwt": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1MjAwMjYzODAsImV4cCI6MTUyMDAyOTk4MH0.19sUG-ncAycxdosaZJDGpkeSfuugmEH_fCPRJtTsOI4"
}

Generates a JWT signed with private key file 'private_key.pem' using the RS256 algorithm.

jwt-generate generate -f private_key.pem -a RS256

{
  "headers": {
    "Authorization": "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpYXQiOjE1MjAwMjYzNTIsImV4cCI6MTUyMDAyOTk1Mn0.AkPpR5BASPD4qY-y_RIkVuaRNTnnA4VCyq7qRPd7nwsbdRGifDlRVJi0RoxyzFAWBkgskTJJK3Zb8v_AF16yp8QkNx00SvTMGOYueFjk2cWxCOneJyJ14K4huflTvqmky5VTpI6Bv5l6ezrpZaWVM9bmpbqI-_QC6A74mFkC5T45WRPXx0K14YCL2lW8UelnRFb8b3y9CdOA088wU4fShLHQvzPS0lzH-WXjfHl5_Dt7AjV8Bwim1sJS1yZudebKV3qEnO9nd4OhMlTeFH2vxevPumtlmmqCf6e5K59x27KcIu7tfkRK81WjX1HP-UiD-p0rpcney3oBDMHcjwIqZQ"
  },
  "jwt": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpYXQiOjE1MjAwMjYzNTIsImV4cCI6MTUyMDAyOTk1Mn0.AkPpR5BASPD4qY-y_RIkVuaRNTnnA4VCyq7qRPd7nwsbdRGifDlRVJi0RoxyzFAWBkgskTJJK3Zb8v_AF16yp8QkNx00SvTMGOYueFjk2cWxCOneJyJ14K4huflTvqmky5VTpI6Bv5l6ezrpZaWVM9bmpbqI-_QC6A74mFkC5T45WRPXx0K14YCL2lW8UelnRFb8b3y9CdOA088wU4fShLHQvzPS0lzH-WXjfHl5_Dt7AjV8Bwim1sJS1yZudebKV3qEnO9nd4OhMlTeFH2vxevPumtlmmqCf6e5K59x27KcIu7tfkRK81WjX1HP-UiD-p0rpcney3oBDMHcjwIqZQ"
}

Outputs the decoded JWT in JSON format.

jwt-generate decode eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1MjAwMjYyOTAsImV4cCI6MTUyMDAyOTg5MH0.lUGQ7n3QTWGLrH-KcMkCWsGlMWxO-QodOEdbGSeZF-A

{
  "header": {
    "typ": "JWT",
    "alg": "HS256"
  },
  "payload": {
    "iat": 1520026290,
    "exp": 1520029890
  },
  "signature": "lUGQ7n3QTWGLrH-KcMkCWsGlMWxO-QodOEdbGSeZF-A"
}

FAQs

Package last updated on 02 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc