Session tokens vs JWTs
Stytch user sessions are identified by a session token (session_token) or session JWT (session_jwt) that should be stored client-side (usually a browser cookie) and authenticated on each request. During each successful session creation or authentication, both a token and a JWT are returned in the API response.
The session token is a unique and opaque 44-character string, while the session JWT is a string that follows standard JWT protocols. The session token and the session JWT are completely interoperable, and both are returned on every API response so that developers can use whichever is best for their application.
For more information, please check out our blog post on the same topic.
Session tokens
These are considered opaque because they don't contain any information about the user or the underlying session
- Session tokens need to be authenticated via the SessionsAuthenticate endpoint before a user takes any action that requires authentication
The session token will not authenticate and will be considered invalid if underlying session is revoked
You might use session tokens if...
Your security needs require that your app must never accidentally use a revoked session (i.e. even the small 5 minute grace period of our default JWTs is not acceptable to your app's security)
Your access to user-side storage is limited and can only store small values
You don't want to expose the session data (authentication factors) or metadata (timestamps) in user storage
JWTs
Contains standard claims as well as information about the Stytch session
- Session JWTs can be authenticated locally without an API call. A session JWT is signed by project-specific keys stored by Stytch. You can retrieve your project's public keyset via our GetJWKS endpoint
- Expires after 5 minutes but can be refreshed via our SessionsAuthenticate endpoint for the duration of the underlying Stytch session
The session JWT will successfully locally validate until the five minute expiration mark, even if the underlying session is revoked. You can always refresh more frequently than that if you prefer
You might use JWTs if...
Your application would benefit from the performance improvements of validating user sessions without an external network request
You're using Stytch sessions to authorize actions outside of your app and that authorization works via JWT
We strongly recommend that you use our Backend SDKs (available in Node, Python, Ruby, and Go) if you are using JWTs. Our libraries handle the logic to authenticate JWTs locally and automatically fall back to the Stytch API when the JWT is expired.