Use cases
Trusted auth tokens support a range of powerful patterns:- 3rd-party SSO integrations: Exchange external identity provider tokens (like Vercel or Zendesk) for Stytch sessions.
- Bring-your-own-auth: Accept JWTs your product already issues.
- Custom auth factors: Add external factors (biometrics, device attestation) and represent them in the Stytch session.
How it works
Configure a Trusted Auth Token Profile
Define the JWT issuer and audience, add public key(s) or a JWKS URL, and map JWT claims to Stytch attributes.
Issue or receive a token
Mint a JWT in your backend or accept one from a 3rd-party identity provider.
Exchange the token for a session
Call the Attest Session endpoint to create or extend a Stytch session.
Configuring a Trusted Auth Token profile
In the Stytch Dashboard, navigate to the Trusted Auth Tokens page. Here you can create a new Trusted Auth Token Profile for the provider of the tokens that you want to attest, or view and edit existing profiles. The issuer (iss) and audience (aud) should match the corresponding values in the JWTs that you are trying to attest.
Attribute mappings are used to tie per-user claims within the JWT to Stytch platform attributes.
The following attribute mappings are available today:
| Attribute | Required | Purpose |
|---|---|---|
| Yes | The email address of the user identified by the JWT | |
| token_id | Yes | A unique identifier for the JWT |
| external_user_id | No | Optional external user ID to attach to the user |
| role_ids | No | Array of RBAC Role IDs to assign |
JIT provisioning
By default, Trusted Auth Tokens cannot be used to create new users, and can only authenticate existing users.To allow tokens to create new users, enable Allow JIT Provisioning in the dashboard.
Exchanging a Trusted Auth Token for a Session
Once you have a profile set up for the source of your trusted auth tokens, you can use the backend API to exchange a token for a Stytch session, or add it as an auth factor for an existing session using the Attest Session API endpoint. The API endpoint is available in all Stytch Backend and Frontend SDKs.Putting it all together
Suppose you configure a Trusted Auth Token Profile with an issuer ofhttps://auth.example.com, an audience of
https://api.example.com and the following attribute mapping:
email:emailtoken_id:jtiexternal_user_id:subroles:assignments
What’s next
- Accept credentials from an External Identity Provider
- Create Trusted Auth Tokens for custom auth factors
- Add custom claims to session JWTs