Session Tokens
KeyStone Elements uses session tokens for browser-safe API access. These are short-lived, scoped JWTs issued by the KeyStone API, separate from the M2M credentials your backend uses.Why Not Use M2M Credentials Directly?
M2M credentials (client_id + client_secret) have full API access for your environment. Exposing them in browser code would let anyone with DevTools access your entire settlement data and create/modify settlements on your behalf. Session tokens solve this by being:- Short-lived - 1 hour default (configurable 1 min to 24 hours)
- Scoped - Limited to specific permissions (e.g., only
settlements:read) - Revocable - Can be invalidated immediately via API
- Auditable - Carry metadata about which end-user is acting
Creating Session Tokens
Your backend creates session tokens by callingPOST /v1/sessions with M2M authentication:
Available Scopes
| Scope | Description |
|---|---|
settlements:read | List and view settlements |
settlements:write | Create settlements, submit compliance decisions |
templates:read | List and view settlement templates |
instructions:read | List and view instructions |
instructions:write | Submit and cancel instructions |
Scoping to Specific Settlements
You can restrict a session token to specific settlement IDs. This is useful when a trader should only see their own settlement:settlementIds list. Attempts to access other settlements return 403.
Token Refresh
Session tokens expire. TheKeystoneProvider supports automatic refresh via the onTokenExpired callback:
Revoking Tokens
Revoke a session token immediately (e.g., on user logout):Security Model
- M2M credentials stay on your backend. Never sent to the browser.
- Session tokens are the only auth mechanism in the browser.
- Each session token is tied to a platform and environment.
- The KeyStone API validates the token on every request and checks revocation status.