Skip to main content
Sessions represent an authenticated user’s active login to an Organization. After a user successfully authenticates, Stytch creates a Session and returns both a session_token and session_jwt that you can use to authorize requests. Sessions have a configurable lifetime (default: 60 minutes) and can be extended by re-authenticating them before they expire. Sessions contain authentication factors and can be revoked at any time.

Common operations

Validate a session and optionally extend its lifetime. Use this to authorize requests in your application.
1

Authenticate with session token

curl --request POST \
  --url https://test.stytch.com/v1/b2b/sessions/authenticate \
  --header 'Content-Type: application/json' \
  --user 'PROJECT_ID:SECRET' \
  --data '{
    "session_token": "mZAYn5aLEqKUlZ_Ad9U_fWr38GaAQ1oFAhT8ds245v7Q",
    "session_duration_minutes": 60
  }'
Parameters:
  • session_token: The session token to validate (use either this or session_jwt)
  • session_jwt: Alternative to session_token - the JWT to validate
  • session_duration_minutes: (Optional) Extend session lifetime by this many minutes
  • session_custom_claims: (Optional) Custom claims to add to the session JWT
  • authorization_check: (Optional) Check RBAC permissions during authentication
Response:
{
  "status_code": 200,
  "request_id": "request-id-test-...",
  "member_session": {
    "member_session_id": "member-session-test-...",
    "member_id": "member-test-32fc5024-9c09-4da3-bd2e-c9ce4da9375f",
    "organization_id": "organization-test-07971b06-ac8b-4cdb-9c15-63b17e653931",
    "started_at": "2024-01-01T00:00:00Z",
    "last_accessed_at": "2024-01-01T01:00:00Z",
    "expires_at": "2024-01-01T02:00:00Z",
    "authentication_factors": [
      {
        "type": "magic_link",
        "delivery_method": "email",
        "email_factor": {
          "email_id": "email-test-...",
          "email_address": "user@example.com"
        }
      }
    ]
  },
  "session_token": "mZAYn5aLEqKUlZ_Ad9U_fWr38GaAQ1oFAhT8ds245v7Q",
  "session_jwt": "eyJhbGc...",
  "member": { /* member object */ },
  "organization": { /* organization object */ }
}
2

Use for request authorization

Store the session_token or session_jwt and include it in subsequent requests to verify the user is authenticated. Call the authenticate endpoint on each request or periodically to validate the session is still active.
You can pass an expired JWT (based on its exp claim) and receive a new JWT if the underlying Session is still valid.

Session tokens vs JWTs

Stytch provides two token formats for sessions:

Session Tokens

Opaque tokens that must be validated server-side via the authenticate endpoint.
  • More secure (can’t be decoded)
  • Requires API call to validate
  • Can be revoked immediately

Session JWTs

JSON Web Tokens that can be validated locally using your project’s public key.
  • Can validate without API calls
  • Contains claims (member ID, org ID, etc.)
  • Slightly delayed revocation (until JWT expires)

Authentication factors

Sessions track which authentication methods were used. Common factors include:
  • Magic Links - Email-based authentication
  • OAuth - Social login (Google, Microsoft, etc.)
  • OTP - One-time passcodes via email or SMS
  • SSO - SAML or OIDC connections
  • Passwords - Traditional password authentication
  • TOTP - Authenticator app codes
  • WebAuthn - Biometric or security key authentication

RBAC authorization checks

You can combine session authentication with RBAC permission checks:
curl --request POST \
  --url https://test.stytch.com/v1/b2b/sessions/authenticate \
  --header 'Content-Type: application/json' \
  --user 'PROJECT_ID:SECRET' \
  --data '{
    "session_token": "mZAYn5aLEqKUlZ_Ad9U_fWr38GaAQ1oFAhT8ds245v7Q",
    "authorization_check": {
      "organization_id": "organization-test-...",
      "resource_id": "documents",
      "action": "delete"
    }
  }'
If the member lacks permission, the API returns a 403 error. Otherwise, the response includes which roles satisfied the authorization.

Next steps