Sign your own tokens
Before you begin
- Plan
- Included in Pro and Team. How plans and limits work
- Role
- Editor or higher.
- You need
- A project with response templating on
Three template helpers work in any mock: jwt signs a token with the project’s key, jwks publishes the keys that verify it, and jwtClaim reads a claim from a token the project signed.
-
Create a mock for
GET /.well-known/jwks.jsonwhose body is:{{jwks}} -
Create a mock for your login, such as
POST /login, whose body signs a token:{"access_token": "{{jwt sub='user-1' aud='my-api' scope='orders:read' expiresIn=3600}}","token_type": "Bearer"}iat,exp,jtiandissare filled in unless you give them;issis the address the caller used. Addalg='ES256'for an ES256 token. -
In a mock your application calls with that token, read a claim back:
{"owner": {{toJson (jwtClaim request.headers.Authorization 'sub' default='anonymous')}}}A leading
Beareris dropped. A token the project did not sign, or one altered or expired, gives thedefault.
Result
Section titled “Result”The login mock answers a token your application verifies against the JWKS mock, and the second mock answers with the token’s sub.
Limits
Section titled “Limits”- Signing needs a plan with the identity provider. On another plan a mock calling
jwt,jwksorjwtClaimfails to render, and the editor warns when you save it. jwtClaimwithoutdefault=fails the response when the token does not verify.- One response signs at most 8 tokens and reads at most 8 different tokens; reading the same token several times counts once.
- Try it signs with a preview key no project’s JWKS lists.