v1.0.1
REST APIv1.0.0
REST Authentication & Sessions
OAuth 2.0 provider integration and HttpOnly session cookies in BehaviorSim API.
BehaviorSim API implements two orthogonal authentication schemes:
- Browser Sessions: Powered by OAuth (Google, GitHub) issuing an encrypted
behaviorsim_sessionHttpOnly cookie. - Programmatic API Keys: Bearer tokens starting with
bs_live_for backend scripts and CLI clients.
Dual Authentication Model
Protected routes (like /v1/account or /v1/simulations) accept either an authenticated browser session cookie or an Authorization Bearer header.
OAuth 2.0 Web Flow
- Initiation: Navigating to
GET /v1/auth/{provider}(whereproviderisgoogleorgithub) generates a CSRF state token and redirects to the identity provider. - Callback: Provider redirects back to
GET /v1/auth/{provider}/callbackwith state and code. - Session Resolution: API exchanges code for user profile, seeds account if new, creates database session record, and sets
behaviorsim_sessioncookie. - Landing Redirect: Redirects browser to the configured frontend destination (
/account).
Session Cookie Specifications
| Property | Value | Security Rationale |
|---|---|---|
| Cookie Name | behaviorsim_session | Identifies session token |
| HttpOnly | true | Prevents JavaScript XSS extraction |
| SameSite | Lax | Protects against Cross-Site Request Forgery |
| Secure | true (in prod) | Encrypted in transit over HTTPS |
| Max-Age | 604800 (7 days) | Automatic expiration window |
Terminating Sessions (Logout)
Issuing POST /v1/auth/logout invalidates the database session and clears the client cookie:
terminal
curl -X POST https://api.behavioursim.vedaangsharma.in/v1/auth/logout \
-H "Accept: application/json" \
--cookie "behaviorsim_session=..."