Token Auth
Use token auth when your app should send Authorization: Bearer <token> on every request instead of raw user/password credentials.
KalamDB supports two token sources:
- KalamDB-issued access and refresh tokens returned by local login or OIDC exchange endpoints
- direct external OIDC ID tokens from the configured trusted issuer
Internal Token Flow
The built-in login flow is:
- Send user and password to
POST /v1/api/auth/login. - Receive
access_tokenandrefresh_token. - Send the access token on API and WebSocket requests.
- Refresh it through
POST /v1/api/auth/refreshwhen needed.
Login
Typical response fields:
access_tokenrefresh_tokenexpires_ator token-expiry metadata- authenticated user profile fields
Use the access token
Refresh Tokens
Use the returned access token for subsequent requests.
Checking Auth State
There are two practical checks:
Check the current authenticated user
This confirms whether the token is accepted and shows the current user record.
Check from SQL
This is the fastest way to confirm the runtime identity that SQL sees.
OIDC Browser And Device Exchange Flows
The Admin UI and CLI normally exchange provider login results for KalamDB-issued tokens.
Endpoints:
POST /v1/api/auth/oidc/exchange-codefor browser Authorization Code + PKCEPOST /v1/api/auth/oidc/exchange-tokenfor direct device login when the CLI obtains a provider ID tokenPOST /v1/api/auth/oidc/device/startandPOST /v1/api/auth/oidc/device/pollfor brokered device flow
CLI entry points:
All three flows return or save KalamDB access and refresh tokens. They do not persist provider credentials.
Direct External Bearer Tokens
If you already have a valid token from the configured trusted OIDC issuer, you can also skip the exchange endpoints and send that provider token directly as a bearer token.
KalamDB will:
- read
algandiss - reject untrusted issuers
- perform OIDC discovery for the issuer
- fetch and cache the issuer JWKS
- validate the token signature and claims
- resolve or create the matching local user
OIDC setup details live in:
SDK Pattern
For long-lived apps, return a fresh token from the SDK auth provider callback instead of hard-coding a token once.
TypeScript
Dart
Configuration Notes
Internal token auth still depends on a strong shared secret:
OIDC also depends on the configured single provider block:
Use KALAMDB_JWT_SECRET and the KALAMDB_AUTH_OIDC_* env vars in production instead of committing secrets to server.toml.