JwtTest is a tiny script that issues a JWT token and also exposes a JWKS endpoint for the verification of the token. Use it to test your JWT verification code or when you are developing a JWT-secured API locally and need to add a token to your requests. This project uses JBang, which will take care of installing all the dependencies for you. These dependencies are:
- Java 11+
- Javalin
- Auth0 Java JWT
- Nimbus JOSE + JWT
- SLF4J with slf4j-simple
Install JBang if not already installed:
curl -Ls https://sh.jbang.dev | bash -s - app setup
Then simply start the script:
jbang run https://github.com/arov00/JwtTest/blob/master/JwtTest.java
Alternatively, you can clone this repository and run the script locally (JBang is still required):
./JwtTest.java
You can verify that the JWKS endpoint is working by running:
curl http://localhost:7000/jwks
The default JWT is fine for demonstration purposes, but you probably want to customize it:
./JwtTest.java --subject SomeUser \
--issuer=MyAwesomeApp \
--audience=AnotherApp \
--audience=YetAnotherApp \
--claim role=ADMIN \
--claim org=MyOrg \
--int-claim age=42 \
--ttl 60
This will issue a JWT with the following payload (the exp
and iat
fields will be different):
{
"sub": "SomeUser",
"aud": [
"AnotherApp",
"YetAnotherApp"
],
"role": "ADMIN",
"org": "MyOrg",
"iss": "MyAwesomeApp",
"exp": 1687433993,
"iat": 1687433933,
"age": 42
}
For a full list of options, run:
./JwtTest.java --help