Which Method Should I Use?
JWT Session Tokens
For frontend apps where users authenticate via Stytch B2B (magic link, SSO, or password).Usage
With React UI Kit
M2M OAuth 2.0
For backend services using OAuth 2.0 Client Credentials flow.Step 1: Get Credentials
Create M2M client credentials in Dashboard → Settings → API Access. Assign scopes based on what the service needs.Step 2: Exchange for Token
Exchange your client credentials for an access token: Token Endpoint:Step 3: Use the Token
Token Caching
M2M tokens expire after 1 hour. Cache and refresh before expiry:Scopes
Request minimum necessary scopes for each service.
Security Best Practices
- Never expose tokens in client-side code — Use a backend proxy for production
- Store secrets in environment variables — Not in code or version control
- Rotate M2M credentials every 90 days — Dashboard → Settings → API Access
- Use HTTPS only — The API rejects HTTP requests
- Scope credentials minimally — Only request permissions you need
Troubleshooting
FAQ
Can I use API keys instead of OAuth?
No. Cuadra AI uses OAuth 2.0 for server-side authentication. M2M credentials function similarly to API keys but require a token exchange step for security.How do I revoke a compromised token?
For M2M: Rotate the client secret in Dashboard → Settings → API Access. For JWT: Revoke the user session in your Stytch dashboard.What’s the token lifetime?
M2M access tokens expire after 1 hour. JWT session tokens follow your Stytch session configuration (typically 24 hours to 30 days).Do I need separate credentials for staging vs production?
Recommended. Create separate M2M clients per environment to isolate access and simplify rotation.Related
API Overview
Base URL, rate limits
Errors
Error handling