Authentication
Ostrakon uses a single authentication system called OSP (One-Shot Password).
How OSP works
Section titled “How OSP works”Unlike traditional passwords, you do not choose your OSP: the server generates it at registration. It stays valid for every login until you regenerate it with /auth/rotate.
Authentication flow
Section titled “Authentication flow”- The user registers (no email), the system returns an initial OSP directly
- The user saves this OSP and logs in with it (as many times as needed)
- The system generates new JWT tokens and a refresh token (HttpOnly cookie)
- To get a new OSP, use
/auth/rotate
┌─────────┐ ┌─────────┐│ User │ │ API │└────┬────┘ └────┬────┘ │ │ │ POST /register │ │───────────────────────>│ │ │ │ {osp, account_id} │ │<───────────────────────│ │ │ │ POST /login {osp} │ │───────────────────────>│ │ │ │ {access_token, ...} │ │<───────────────────────│ │ │JWT tokens
Section titled “JWT tokens”After login, you receive two tokens:
| Token | Lifetime | Usage |
|---|---|---|
| Access Token | 15 minutes | Authenticate API requests |
| Refresh Token | 7 days | Get a new access token |
Using the Access Token
Section titled “Using the Access Token”Add it to the Authorization header:
curl https://ostrakon.example.com/api/v1/triggers \ -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIs..."Refreshing the token
Section titled “Refreshing the token”When the access token expires, use the refresh token:
curl -X POST https://ostrakon.example.com/api/v1/auth/refresh \ -H "Content-Type: application/json" \ -d '{ "refresh_token": "eyJhbGciOiJIUzI1NiIs..." }'Response:
{ "access_token": "new-access-token", "refresh_token": "new-refresh-token", "expires_in": 900}The refresh token is single-use: each refresh replaces it with a new one, and replaying an old token revokes the whole session (reuse detection).
Grace window: two concurrent refreshes (two tabs, a retry) carry the same token. If the old token is replayed within 10 seconds (auth.refresh_reuse_grace) of its rotation, its direct successor is still valid and the session is not revoked, the API returns only a new access_token: no refresh_token and no cookie, and the client keeps the successor received in the first response. Outside the window, or if the successor has already been used, it counts as reuse and the session is revoked. 0 disables the grace window.
OSP rotation
Section titled “OSP rotation”If you lost your OSP, you can regenerate it (while logged in):
curl -X POST https://ostrakon.example.com/api/v1/auth/rotate \ -H "Authorization: Bearer VOTRE_ACCESS_TOKEN"Response:
{ "message": "OSP rotated successfully. Refresh tokens revoked, old OSP no longer valid. ...", "osp": "new-osp"}Rotation requires a JWT: an API key cannot do it.
Warning: This revokes all your refresh tokens and the old OSP can no longer be used to log in. Access tokens already issued remain valid until they expire (15 minutes at most).
Logout
Section titled “Logout”Simple logout
Section titled “Simple logout”Invalidates only the refresh token provided (the server reads the bc_refresh cookie first, then the refresh_token field of the body):
curl -X POST https://ostrakon.example.com/api/v1/auth/logout \ -H "Authorization: Bearer VOTRE_ACCESS_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "refresh_token": "your-refresh-token" }'Logout of all sessions
Section titled “Logout of all sessions”Invalidates all the refresh tokens of your account. This route requires a JWT: an API key gets a 403:
curl -X POST https://ostrakon.example.com/api/v1/auth/logout-all \ -H "Authorization: Bearer VOTRE_ACCESS_TOKEN"Sessions, history and account deletion
Section titled “Sessions, history and account deletion”These routes require a JWT (no API key):
GET /auth/sessionslists the active sessions (id,device,ip,created_at,last_seen_at,expires_at,current),DELETE /auth/sessions/{id}revokes one.GET /auth/login-historyreturns the history of logins, logouts and rotations (event_type,success,ip,device,created_at).DELETE /auth/accountdeletes the account and all its data, irreversibly. The body must contain your OSP:{"osp": "your-osp"}.202response: access is cut off immediately, the erasure finishes in the background.
Security best practices
Section titled “Security best practices”- Never share your OSP - It is your only password
- Store tokens securely - Use httpOnly cookies or secure storage
- Use API Keys for servers - No user tokens server-side
- Implement automatic refresh - Refresh before expiry
- Log out properly - Invalidate unused tokens