Skip to content

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.

  1. Create a mock for GET /.well-known/jwks.json whose body is:

    {{jwks}}
  2. 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, jti and iss are filled in unless you give them; iss is the address the caller used. Add alg='ES256' for an ES256 token.

  3. In a mock your application calls with that token, read a claim back:

    {"owner": {{toJson (jwtClaim request.headers.Authorization 'sub' default='anonymous')}}}

    A leading Bearer is dropped. A token the project did not sign, or one altered or expired, gives the default.

The login mock answers a token your application verifies against the JWKS mock, and the second mock answers with the token’s sub.

  • Signing needs a plan with the identity provider. On another plan a mock calling jwt, jwks or jwtClaim fails to render, and the editor warns when you save it.
  • jwtClaim without default= 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.

Report a problem with this page