Sign-in and sessions
End users sign in against the Core Proxy, which checks the password (bcrypt), mints
the session token and later validates it on every call. The token is a JWT signed HS256
with the deployment’s JWT_SECRET, so the Control Plane, which shares the secret, can read
it too. There is no SSO or OIDC login route on the Portal API: end users sign in with a
username and password, plus a TOTP code if they enabled 2FA.
Log in
Section titled “Log in”-
Post the credentials. No token yet, so
X-Tenant-IDis what names the tenant.Terminal window curl -s http://localhost:8100/v1/portal/auth/login \-H "Content-Type: application/json" \-H "X-Tenant-ID: default" \-d '{"username": "underwriter", "password": "Underwriter123!"}'r = requests.post(f"{BASE}/v1/portal/auth/login",headers={"X-Tenant-ID": TENANT},json={"username": "underwriter", "password": "Underwriter123!"},timeout=30,)r.raise_for_status()data = r.json()const res = await fetch(`${BASE}/v1/portal/auth/login`, {method: "POST",headers: { "Content-Type": "application/json", "X-Tenant-ID": TENANT },body: JSON.stringify({ username: "underwriter", password: "Underwriter123!" }),});if (!res.ok) throw new Error(`login failed: ${res.status}`);const data = await res.json();Response
200when the account has no 2FA:{"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0eXAiOiJwb3J0YWwi...","token_type": "bearer","expires_in": 3600,"user": {"id": "2","username": "underwriter","email": "underwriter@borealis.example","display_name": "Anna Berg (Underwriter)","is_verified": true,"created_at": "2026-10-28T16:22:11.675662Z","last_login": "2026-10-28T16:26:25.469606Z","metadata": null,"avatar_url": null,"totp_enabled": false,"primary_group_id": "group-01M61N376V2RR6J2TV7Q7EVRET"}}The same
userobject comes back from/validate,/profileand the 2FA step. Keepprimary_group_id: it seeds the active workspace (see Workspaces). It can benullfor a user an admin added to a group without stamping a primary one. -
Handle the 2FA branch. When the user has TOTP enabled, the password alone returns a challenge instead of a session:
{"requires_2fa": true,"temp_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0eXBlIjoicG9ydGFsXzJmYV9jaGFsbGVuZ2Ui...","user": {"username": "underwriter","email": "underwriter@borealis.example","display_name": "Anna Berg (Underwriter)"}}The
temp_tokenis valid for 5 minutes and works nowhere except the next call. Prompt for the 6-digit code from the authenticator app, or one of the backup codes:Terminal window curl -s http://localhost:8100/v1/portal/auth/login/2fa \-H "Content-Type: application/json" \-H "X-Tenant-ID: default" \-d '{"temp_token": "eyJ0eXAiOiJKV1Qi...", "code": "492817"}'if data.get("requires_2fa"):code = input("Authenticator code: ")r = requests.post(f"{BASE}/v1/portal/auth/login/2fa",headers={"X-Tenant-ID": TENANT},json={"temp_token": data["temp_token"], "code": code},timeout=30,)r.raise_for_status()data = r.json()portal.jwt = data["access_token"]let login = data;if (login.requires_2fa) {const code = await promptForTotp(); // your UIconst r = await fetch(`${BASE}/v1/portal/auth/login/2fa`, {method: "POST",headers: { "Content-Type": "application/json", "X-Tenant-ID": TENANT },body: JSON.stringify({ temp_token: login.temp_token, code }),});if (!r.ok) throw new Error(`2FA failed: ${r.status}`);login = await r.json();}session.jwt = login.access_token;The response is the normal login response plus
"used_backup_code": true|false. A backup code works once; when one was used, tell the user how many remain (GET /v1/portal/auth/2fa/status). -
Store the token and send it on every call as
Authorization: Bearer <jwt>(andX-Gateway-Authorization: Bearer <jwt>), withX-Tenant-ID. The shipped portal keeps it inlocalStorage(user_auth_token) and reads it back on reload.
| Login failure | Status | Body |
|---|---|---|
| Unknown user or wrong password | 401 |
{"error": "Invalid username or password"} |
| Account deactivated by an admin | 403 |
{"error": "User account is inactive"} |
| 10 failed attempts for the same username within 5 minutes | 429 |
{"error": "Too many failed attempts. Try again shortly."} |
| Wrong or expired 2FA code / challenge | 401 |
{"error": "Invalid 2FA code"} or {"error": "Invalid or expired 2FA challenge"} |
What is in the token
Section titled “What is in the token”Decode the payload (base64url, not base64; use a JWT library such as jwt-decode) to read
the expiry. Do not trust it for anything else: the proxy re-validates the token on every
call.
{ "typ": "portal", "user_id": "2", "tenant_id": "default", "email": "underwriter@borealis.example", "username": "underwriter", "user_type": "end_user", "permissions": null, "admin_type": null, "exp": 1793208385, "iat": 1793204785, "jti": "17973f0e-63c3-402e-a982-e7259e760ef7"}| Claim | Example | Meaning |
|---|---|---|
typ |
portal |
Portal session token. Portal routes refuse any other token with “a portal session token is required” |
user_id |
2 |
The end user (numeric id, as a string) |
tenant_id |
default |
The tenant; a token replayed against another tenant is refused |
user_type |
end_user |
Always end_user for portal tokens |
exp / iat |
1793208385 |
Expiry and issue time, Unix seconds. Lifetime is JWT_EXPIRES_IN (default 3600) |
jti |
17973f0e-63c3-... |
Session id. Logout revokes it; a portal token without one is refused |
There is no refresh token. When exp passes, or any call answers 401, send the user back
to the login screen. The shipped portal checks exp before each request and warns in the
console 5 minutes ahead.
Validate a stored token on startup
Section titled “Validate a stored token on startup”POST /v1/portal/auth/validate (no body) tells you whether a token restored from storage is
still good, and returns the current user:
curl -s -X POST http://localhost:8100/v1/portal/auth/validate \ -H "X-Tenant-ID: default" \ -H "Authorization: Bearer $JWT"{ "valid": true, "user": {"id": "2", "username": "underwriter", "email": "underwriter@borealis.example", "display_name": "Anna Berg (Underwriter)", "is_verified": true, "created_at": "2026-10-28T16:22:11.675662Z", "last_login": "2026-10-28T16:26:25.469606Z", "metadata": null, "avatar_url": null, "totp_enabled": false, "primary_group_id": "group-01M61N376V2RR6J2TV7Q7EVRET"}}An expired, revoked or foreign token answers 401 with WWW-Authenticate: Bearer.
Log out
Section titled “Log out”POST /v1/portal/auth/logout revokes the token on the server: its jti is recorded,
and every surface that accepts a portal token (portal routes, chat, tools) refuses it from
then on with “portal session has been logged out”. Clear your local copy as well.
curl -s -X POST http://localhost:8100/v1/portal/auth/logout \ -H "X-Tenant-ID: default" \ -H "Authorization: Bearer $JWT"{"success": true, "message": "Logged out successfully"}If the revocation cannot be written, the call answers 500 “Logout could not be
recorded; the session is still active”. Tell the user rather than pretending they are
signed out.
Self-registration
Section titled “Self-registration”POST /v1/portal/auth/register needs no token, only X-Tenant-ID. A new user belongs to
no resource group, so they see no models until an admin adds them to one
(Users, groups & API keys).
curl -s http://localhost:8100/v1/portal/auth/register \ -H "Content-Type: application/json" \ -H "X-Tenant-ID: default" \ -d '{"username": "jane", "email": "jane@example.com", "password": "s3cret-pass", "display_name": "Jane Doe"}'Response 201:
{"id": 7, "username": "jane", "email": "jane@example.com", "display_name": "Jane Doe", "created_at": "2026-10-28T17:02:11.104Z"}| Field | Example | Rule |
|---|---|---|
username |
jane |
Required, 1 to 100 characters, unique in the tenant (400 “Username already taken”) |
password |
s3cret-pass |
Required, at least 8 characters |
email |
jane@example.com |
Optional, unique in the tenant (400 “Email already registered”) |
display_name |
Jane Doe |
Optional |
avatar_url |
https://avatars.example.com/jane.png |
Optional external picture |
photo_base64 + photo_mime_type |
iVBORw0KGgo... + image/png |
Optional inline photo; MIME one of image/jpeg, image/png, image/webp, image/gif. Wins over avatar_url |
Profile and password
Section titled “Profile and password”| Method | Path | Body | Response |
|---|---|---|---|
| GET | /v1/portal/auth/profile |
The user object |
|
| PATCH | /v1/portal/auth/profile |
{"email": "anna.berg@borealis.example", "display_name": "Anna Berg", "metadata": {"theme": "dark"}} (all optional) |
The updated user object |
| POST | /v1/portal/auth/profile/photo |
multipart, field file, at most 5 MB, JPEG/PNG/WebP/GIF |
{"success": true, "avatar_url": "/v1/assets/users/end-user/2/photo?h=..."} |
| POST | /v1/portal/auth/change-password |
{"current_password": "Underwriter123!", "new_password": "a-longer-passphrase"} |
{"success": true, "message": "Password changed successfully"} |
metadata is free-form JSON for your client’s own preferences. A new password must be at
least 8 characters; a wrong current password answers 400 “Current password is
incorrect”. For the photo upload, let the HTTP library set the multipart
Content-Type boundary; do not set it yourself.
Let users turn on 2FA
Section titled “Let users turn on 2FA”-
POST /v1/portal/auth/2fa/setup(no body) starts enrollment and returns the secret and a QR code to show:{"secret": "JBSWY3DPEHPK3PXPJBSWY3DPEHPK3PXP","provisioning_uri": "otpauth://totp/Brutor%20(default):underwriter%40borealis.example?secret=JBSW...&issuer=Brutor%20(default)","qr_code": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."}Render
qr_codedirectly as an<img src>.409means 2FA is already on. -
POST /v1/portal/auth/2fa/verifywith{"code": "492817"}from the app turns it on and returns the backup codes once:{"enabled": true,"backup_codes": ["7F3KQ9XM2H", "PL4WZNB8RT", "..."],"message": "2FA enabled. Save these backup codes — they won't be shown again."}A wrong code answers
401“Invalid verification code”. -
GET /v1/portal/auth/2fa/statusreports{"enabled": true, "verified_at": "2026-10-28T17:10:02Z", "backup_codes_remaining": 10}.POST /v1/portal/auth/2fa/disablewith a current TOTP code ({"code": "113094"}) answers{"enabled": false, "message": "2FA has been disabled."}.
TOTP is RFC 6238: SHA-1, 6 digits, 30-second step. Ten backup codes of 10 upper-case letters and digits are issued and stored bcrypt-hashed; they are matched case-insensitively.
Brand the login screen
Section titled “Brand the login screen”Before anyone signs in, fetch the tenant’s theme so the login screen uses the operator’s
colours and logo. No authentication; unknown or suspended tenants answer 404.
curl -s http://localhost:8100/v1/public/tenants/default/theme{ "tenant_id": "default", "company_name": "Borealis Consumer Finance", "variants": { "portal_light": {"primary_color": "#1BB5E8", "secondary_color": "#87ceeb", "background_color": "#ffffff", "surface_color": "#f8f9fa", "border_color": "#e0e0e0", "text_primary": "#000000", "text_secondary": "#666666", "logo_url": null, "favicon_url": null, "company_name": "Borealis Consumer Finance"}, "portal_dark": {"primary_color": "#1BB5E8", "background_color": "#0f172a", "...": "..."}, "admin_light": {"...": "..."}, "admin_dark": {"...": "..."} }}Use the portal_light and portal_dark variants; the admin_* ones style the Admin UI.
Related
Section titled “Related”- Workspaces and catalogs: the next step after sign-in
- Portal API reference: authentication
- Users, groups & API keys: how admins create end users

