Skip to content

Authentication

Ostrakon uses a single authentication system called OSP (One-Shot Password).

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.

  1. The user registers (no email), the system returns an initial OSP directly
  2. The user saves this OSP and logs in with it (as many times as needed)
  3. The system generates new JWT tokens and a refresh token (HttpOnly cookie)
  4. To get a new OSP, use /auth/rotate
┌─────────┐ ┌─────────┐
│ User │ │ API │
└────┬────┘ └────┬────┘
│ │
│ POST /register │
│───────────────────────>│
│ │
│ {osp, account_id} │
│<───────────────────────│
│ │
│ POST /login {osp} │
│───────────────────────>│
│ │
│ {access_token, ...} │
│<───────────────────────│
│ │

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

Add it to the Authorization header:

Terminal window
curl https://ostrakon.example.com/api/v1/triggers \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIs..."

When the access token expires, use the refresh token:

Terminal window
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.

If you lost your OSP, you can regenerate it (while logged in):

Terminal window
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).

Invalidates only the refresh token provided (the server reads the bc_refresh cookie first, then the refresh_token field of the body):

Terminal window
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"
}'

Invalidates all the refresh tokens of your account. This route requires a JWT: an API key gets a 403:

Terminal window
curl -X POST https://ostrakon.example.com/api/v1/auth/logout-all \
-H "Authorization: Bearer VOTRE_ACCESS_TOKEN"

These routes require a JWT (no API key):

  • GET /auth/sessions lists the active sessions (id, device, ip, created_at, last_seen_at, expires_at, current), DELETE /auth/sessions/{id} revokes one.
  • GET /auth/login-history returns the history of logins, logouts and rotations (event_type, success, ip, device, created_at).
  • DELETE /auth/account deletes the account and all its data, irreversibly. The body must contain your OSP: {"osp": "your-osp"}. 202 response: access is cut off immediately, the erasure finishes in the background.
  1. Never share your OSP - It is your only password
  2. Store tokens securely - Use httpOnly cookies or secure storage
  3. Use API Keys for servers - No user tokens server-side
  4. Implement automatic refresh - Refresh before expiry
  5. Log out properly - Invalidate unused tokens