Sessions
Authenticate JWT
Authenticate a session using a JSON Web Token (JWT)
Given a Session , this method authenticates a Session and updates its lifetime by the specified
If you provide a JWT that needs to be refreshed and is expired according to its
session_duration_minutes. If session_duration_minutes is not specified, the Session will not be extended.
This method is only available when using our backend SDKs.If you are looking for client side JWT authentication, please use the frontend SDKs’ Authenticate Session endpoint instead.
exp claim, a new JWT will be returned if both the signature and the underlying Session are still valid. See our JWT guides for more information.
If the JWT is older than max_token_age_seconds or if the JWT is expired, this method will communicate with the Stytch API to authenticate the session. Otherwise, the JWT will be validated locally.
Local JWT validation
If you do not provide amax_token_age_seconds parameter, then the authenticateJwt method will only communicate with the Stytch API if the JWT is expired (Stytch JWTs have an exp of five minutes). Specifying a max_token_age_seconds parameter of less than five minutes is one way to reduce security risks inherent to local JWT validation by forcing communication with the Stytch API more frequently.
We recommend relying primarily on this method over the authenticateSession method, as it handles the local JWT validation vs. remote session authentication logic for you, improving latency when the JWT is less than max_token_age_seconds old and authenticating the underlying session with Stytch when necessary.
Authorization
If anauthorization_check is passed in, this method will also check if the is authorized to perform the given action on the given Resource in the specified . A Member is authorized if:
- their Member Session contains a Role, assigned explicitly or implicitly, with adequate permissions.
- the
organization_idpassed in the authorization check matches Member Session’s Organization.
403 error will be thrown. Otherwise, the response will contain a list of Roles that satisfied the authorization check.
Request Parameters
The Session JWT to authenticate.
If included, this method will also check if the Member is authorized to perform the given action on the given Resource in the specified Organization. A Member is authorized if their Member Session contains a Role, assigned explicitly or implicitly, with adequate permissions. In addition, the
organization_id passed in the authorization check must match the Member’s Organization.If set, remote verification will be forced if the JWT was issued more than that many seconds ago (based on the
iat claim).Response
The Session object associated with the authenticated JWT.
A new JWT for the authenticated Session.
An opaque Session token for the authenticated Session.Will only be returned when remote JWT authentication occurs.
The Member object associated with the authenticated Session.Will only be returned when remote JWT authentication occurs.
The Organization object associated with the authenticated Session.Will only be returned when remote JWT authentication occurs.
If an
authorization_check is provided in the request and the check succeeds, this field will return information about why the Member was granted permission.The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g. 2XX values
equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors.
Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we
may ask for this value to help identify a specific API call when helping you debug an issue.