access_token or id_token. Stytch will use the JWKS endpoint hosted by your existing infrastructure to validate these JWTs and provision users automatically as required — no additional setup is needed.
If your identity infrastructure does not provide a JWT, you can create your own JWT using a private key.
Minting a JWT and logging in
Generate a public-private key pair
Use a library such as OpenSSL to generate an RSA public-private keypair.The public key can be added to your Trusted Auth Token profile in the Stytch dashboard here; (in the JWKS URL row, click “Use public keys instead”).
The private key should be kept secret, and exposed to your application using an environment variable.
It is often useful to base64 encode the private key for easy addition to
The private key should be kept secret, and exposed to your application using an environment variable.
It is often useful to base64 encode the private key for easy addition to
.env files.Create and sign a JWT
Use any compatible JWT library to sign your JWT with your private key.
Here is an example using jose, a popular library in the Node ecosystem.
Be sure to set the
Choose a short expiry for the JWT - 5 minutes is a good default.Other claims (
Remember, an email and a token ID are required. All other fields are optional.
Here is an example using jose, a popular library in the Node ecosystem.
Be sure to set the
iss and aud claims to match the issuer and audience configured in your Trusted Auth Token Profile.Choose a short expiry for the JWT - 5 minutes is a good default.Other claims (
email, sub, role_ids, jti, etc… ) should be set according to your previously configured attribute mapping.Remember, an email and a token ID are required. All other fields are optional.
Logging a user in
After you have minted your JWT, call the Attest Session API endpoint to exchange the JWT for a Stytch Session.
Adding custom auth factors
To add custom auth factors to an existing flow, call the Attest Session API endpoint with asession_token or session_jwt to attach the attestation to an existing session instead of creating a new one.
It may be useful to pass in a unique token_id to the JWT to tie the custom authentication factor you validated to the session for later reference.