Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jwtjs

The JWT helpers for NodeJS. This repo shows how to create JWKS file and server with Docker in detail.

Create private & public key

Create private key:

$ ssh-keygen -t rsa -b 2048 -m PEM -f private.pem

Generate public key:

$ ssh-keygen -f private.pem -e -m PEM > public.pem

Create JWKS

Create JWK from public.pem

$ node src/createjwks.js --path ./public.pem
{
    "kty": "RSA",
    "kid": "cee00230af4b4f3d86b24cf56592d211",
    "alg": "RS256",
    "n": "AMveSeHOKgI0G...",
    "e": "AQAB"
}

Create jwks.json and put the above in:

{
    "keys": [
        {
            "kty": "RSA",
            "kid": "cee00230af4b4f3d86b24cf56592d211",
            "alg": "RS256",
            "n": "AMveSeHOKgI0G...",
            "e": "AQAB"
        }
    ]
}

Create JWKS server

Build your own docker image with the demo Dockerfile:

$ docker build -t jwksserver .

Start and run the jwksserver:

$ docker run -dit --name jwksserver -p 8080:8080 jwksserver

Check whether it works:

$ curl http://localhost:8080/.well-known/jwks.json
{
    "keys": [
        {
            "kty": "RSA",
            "kid": "cee00230af4b4f3d86b24cf56592d211",
            "alg": "RS256",
            "n": "AMveSeHOKgI0G...",
            "e": "AQAB"
        }
    ]
}

Sign a JWT with private key

Sign JWT with private.pem

$ node src/sign.js --path ./private.pem

About

The JWT methods for NodeJS.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages