A simple web application to create and verify JSON Web Tokens (JWT). Support is currently limited to JSON Web Signature (JWS) and not JSON Web Encryption (JWE).
All JWTs that are created will contain at least the following claims:
aud, exp, iat, and issAlthough these claims are all optional as defined by RFC 5741, all JWTs inspected by the application for verification must contain these claims.
To create a JWT without any client specific information, simply create a POST request to the /create endpoint.
[user@host]# curl -s http://localhost/create -X POST | jq
{
"code": 201,
"token": "eyJhbGciOiJIUzI1NiIsImtpZCI6IjAwMSIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJleGFtcGxlLmNvbSIsImlhdCI6MTYxMDQwMjQxNywiZXhwIjoxNjEwNDA2MDE3LCJhdWQiOiJleGFtcGxlLmNvbSJ9.g2gwfU3AkDhSSinwwpaiTQeMaGzEBAwTtS-0ylCJ7Fg"
}
To create a JWT with specific client information to be encoded as a claim, create a POST request to the /create endpoint with the Content-Type header set to application/json and a JSON encoded request body. The JSON key/value pairs will be encoded as claims.
[user@host]# curl -s http://localhost/create -X POST -H "Content-Type: application/json" -d '{"email":"[email protected]","name":"user"}' | jq
{
"code": 201,
"token": "eyJ0eXAiOiJKV1QiLCJraWQiOiIwMDEiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJleGFtcGxlLmNvbSIsImV4cCI6MTYxMDQwNjA4NywiZW1haWwiOiJ1c2VyQGV4YW1wbGUuY29tIiwibmFtZSI6InVzZXIiLCJpYXQiOjE2MTA0MDI0ODcsImF1ZCI6ImV4YW1wbGUuY29tIn0.aB8sMfR0idbTutV6KJVpiRX-KbqteSSoakF0cZsDIDQ"
}
In order to verify an existing JWT, the client must send the token as part of a specific request header or JSON encoded requst body. The order of operation in which tokens are located in the request is as follows:
Authorization header using the format Authorization: Bearer <jwt>
JWT_TOKEN environment variableCookie header with the name auth_token
JWT_TOKEN environment variabletoken
JWT_TOKEN environment variableOnce a JWT is located in the request, searching ceases immediately and the token is processed for verification.
To verify a JWT using the Authorization header, send a GET request to the /verify endpoint using the format Authorization: Bearer <jwt>.
[user@host]# curl -s http://localhost/verify -H "Authorization: Bearer eyJraWQiOiIwMDEiLCJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE2MTA0MDI0MTEsImlzcyI6ImV4YW1wbGUuY29tIiwiYXVkIjoiZXhhbXBsZS5jb20iLCJleHAiOjE2MTA0MDYwMTF9.bkG47ODMf9X77GcRZAIXf2E-fzPWI-C4N04lkaJxayI" | jq
{
"claims": {
"iat": 1610402411,
"iss": "example.com",
"aud": "example.com",
"exp": 1610406011
},
"code": 200
}
To verify a JWT using the Cookie header, send a GET request to the /verify endpoint using the format Cookie: auth_token=<jwt>.
[user@host]# curl -s http://localhost/verify -H "Cookie: auth_token=eyJraWQiOiIwMDEiLCJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE2MTA0MDI0MTEsImlzcyI6ImV4YW1wbGUuY29tIiwiYXVkIjoiZXhhbXBsZS5jb20iLCJleHAiOjE2MTA0MDYwMTF9.bkG47ODMf9X77GcRZAIXf2E-fzPWI-C4N04lkaJxayI" | jq
{
"claims": {
"iat": 1610402411,
"iss": "example.com",
"aud": "example.com",
"exp": 1610406011
},
"code": 200
}
To verify a JWT using a JSON encoded request body, send a POST request to the /verify endpoint with the Content-Type header set to application/json and a JSON key token set to the token value.
[user@host]# curl -s http://localhost/verify -X POST -H "Content-Type: application/json" -d '{"token":"eyJraWQiOiIwMDEiLCJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE2MTA0MDI0MTEsImlzcyI6ImV4YW1wbGUuY29tIiwiYXVkIjoiZXhhbXBsZS5jb20iLCJleHAiOjE2MTA0MDYwMTF9.bkG47ODMf9X77GcRZAIXf2E-fzPWI-C4N04lkaJxayI"}' | jq
{
"claims": {
"iat": 1610402411,
"iss": "example.com",
"aud": "example.com",
"exp": 1610406011
},
"code": 200
}
The application can be configured by passing environment variables to the container.
uri pathstring/BASE_PATH=/api/jwt/Appends a prefix path to the
/createand/verifyendpoints.Example: the default
/createand/verifyendpoints will become/api/jwt/createand/api/jwt/verify.
HS256, HS384, HS512RS256, RS384, RS512PS256, PS384, PS512ES256, ES256K, ES384, ES512EdDSAstringHS256JWT_ALG=RS256Specifies the algorithm used for signing. Only one algorithm can be specified at a time.
aud claimstringexample.comJWT_AUD=my.example.comSpecifies the value of the aud claim for creating and verifying tokens.
claimsjson stringnullJWT_CLAIMS='{"groups":["admin","everyone"]}'Appends specified claims information to all tokens that are created.
exp claimint3600JWT_EXP=7200Specifies the relative expiration time value of the exp claim for creating tokens. The calculated claim value is
exp = current time + relative expiration.
iss claimstringexample.comJWT_AUD=my.example.comSpecifies the value of the iss claim for creating and verifying tokens.
jwks filestringnullJWT_JWK=./keys/jwks/keys.jwksSpecifies the location of a JSON Web Key Set (RFC 7517) used for token verification.
hmac jwk file, hmac secretrsa jwk file, rsa key fileec jwk file, ec key fileed jwk file, ed key filestringexample123JWT_KEY=hmac_secret or JWT_KEY=./keys/rsa/rs256/rsa.keySpecifies the location of a key file or plain text secret used for signing. Only one key or secret can be specified at a time.
key idstring001JWT_KID=002Specifies the value of the kid header parameter for creating tokens.
claimsjson stringnullJWT_MUTE_CLAIMS='["email","username"]'Removes specified claims information from all tokens that are created.
Example: if you set
JWT_SUB=email, thesubclaim will become the value of the{"email":"[email protected]","username":"user"}). Bothusernameclaims will be dropped from token creation.
claim namestringnullJWT_SUB=emailSpecifies the name of the claim used to set the
subclaim value.Example: the sub claim will become the value of the email key that is passed in the JSON encoded request body (e.g. {"email":"[email protected]","username":"user"}). See also
JWT_MUTE_CLAIMS.
json objectstringnullJWT_TOKEN='{"header":["x-jwt"],"cookie":["jwt"],"body":["jwt"]}';Specifies custom header, cookie, and body parameters to search for token verification.
Example: if a token is not found in the default header, cookie, and body values, the application will search for tokens in the
X-JWTheader,jwtcookie, and JSON request body with key namejwt.
The follownig sample signing keys are included in the /var/www/keys (or relative path ./keys) directory.
| Algorithm | Key ID | Relative Path |
|---|---|---|
HS256 | 001 | ./keys/hmac/hs256/hmac.jwk |
HS384 | 002 | ./keys/hmac/hs384/hmac.jwk |
HS512 | 003 | ./keys/hmac/hs512/hmac.jwk |
RS256 | 004 | ./keys/rsa/rs256/rsa.(jwk|key) |
RS384 | 005 | ./keys/rsa/rs384/rsa.(jwk|key) |
RS512 | 006 | ./keys/rsa/rs512/rsa.(jwk|key) |
PS256 | 007 | ./keys/rsa/ps256/rsa.(jwk|key) |
PS384 | 008 | ./keys/rsa/ps384/rsa.(jwk|key) |
PS512 | 009 | ./keys/rsa/ps512/rsa.(jwk|key) |
ES256 | 010 | ./keys/ec/es256/ec.(jwk|key) |
ES256 | 011 | ./keys/ec/es256k/ec.(jwk|key) |
ES384 | 012 | ./keys/ec/es384/ec.(jwk|key) |
ES512 | 013 | ./keys/ec/es512/ec.(jwk|key) |
EdDSA | 014 | ./keys/dsa/ed25519/dsa.jwk |
A matching JWKS file is located at /var/www/keys/jwks/keys.jwks (or relative path ./keys/jwks/keys.jwks).
There are two versions of this container image to allow for execution in unprivileged environments.
| Tag | UID | GID | Ports |
|---|---|---|---|
latest | root | root | 80, 443 |
latest-unprivileged | nginx | nginx | 8080, 8443 |
Content type
Image
Digest
sha256:13462a6eb…
Size
73.7 MB
Last updated
about 3 years ago
docker pull kryshakm/jwt