GithubHelp home page GithubHelp logo

util.jwt's Introduction

JWT Utilities

Overview

A small set of utilities for generating JWT tokens for authentication.

Prepare an Environment File

The token generation process consumes values configured in a .env file using the dotenv-safe module.

See the .env.example file for the required variables.

Generate a JWT Token

Uses ansible to manage access the private key (from HashiVault), and generates a token using the jsonwebtoken module.

ansible-playbook generate.yaml

NOTE:

  • The generated token will be printed by ansible to stdout.
  • Tokens are sensitive and should be handled like any other password or secret

Prerequisites

The following steps were fillowed to prepare to generate tokens.

Create an RSA Key Pair

ssh-keygen -t rsa -b 4096 -m PEM -f jwtRS256.key -q -N ""

Convert Public Key to PEM Format

openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.key.pub

Generate JWK from Public Key

pem-jwk jwtRS256.key.pub > jwk.json

Create JWKs Containing the JWK

A kid is used to uniquely identify a specific key in an array of supported keys. This value will be used in the header of a JWK as part of the authentication proces.

Create a jwks.json file as follows.

{
  "keys": [
    {
      "kid": "intdev"
      // fields from generated JWK
    }
  ]
}

This JWKS file can be published to a public URL accessible by an API Gateway such as Citrix ADC.

JWT Details

A JWT has 3 parts in the format of xxxxx.yyyyy.zzzzz.

First, the header:

  • typ: "JWT" "(optional)
  • kty: "RSA" (optional)
  • alg: "RSA256"
  • kid: "uid for key in keyset"

Second, the payload:

  • iss: The principal that issued this JWT
  • sub: The principal that is the subject of the JWT
  • aud: The recipients that the JWT is intended for
  • iat: The time at which the JWT was issued
  • exp: The time on/after which the JWT MUST NOT be accepted (unix epoc in seconds)

... other public claims

  • name: Descriptive name of the subject in sub

Third, the signature:

  • NOTE: this is managed by the key generation process

For more details, see:

util.jwt's People

Stargazers

Samuel Demirdjian avatar

Watchers

Mark Holmes avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.