Skip to Content
🎉 BSH Engine v0.0.7 is out with new features and improvements. See what's new →

Sessions

Every login opens an auth session on the engine. Sessions let users stay logged in for weeks while the tokens they send stay short-lived, and they can be ended from the server at any time.

Session and tokens

Lifetime (default)Configured byPurpose
Session30 daysauth.config.sessionTtl (days)Absolute limit. After it, the user logs in again. Refreshing doesn’t extend it.
Access token15 minutesauth.config.accessTtl (minutes)Sent on every request (Authorization: Bearer … or bsh_access_token cookie).
Refresh token7 daysauth.config.refreshTtl (days)Used to get new tokens for the same session (X-BSH-REFRESHTOKEN header or bsh_refresh_token cookie).

Both tokens only carry the user id (sub), the session id (sid) and a token id (jti). Use GET /api/users/me to fetch user details.

Token expiry is based on the TTLs currently configured, so changing accessTtl or refreshTtl also applies to tokens already issued.

Lifecycle

StatusWhen
ActiveThe session can be used and refreshed.
LoggedOutThe user called Logout with this session.
RevokedThe session was revoked from another session, or by a BSH_ADMIN.
ExpiredThe session reached sessionTtl, or was idle for longer than refreshTtl.
BlockedRotated or unknown tokens of this session were used too many times, a sign the tokens were stolen. See Token rotation.

When the engine closes a session itself, it records why in the session’s reason field.

Token rotation

Each refresh, automatic or through POST /api/auth/refresh, issues a new access token and a new refresh token for the same session.

  • The previous refresh token keeps working for 10 seconds, so requests sent in parallel don’t fail.
  • After that, using it again is treated as a stolen token: the whole session is closed as Expired.

Clients that store tokens themselves must save both new tokens after each refresh. Keeping the old refresh token logs the user out on the next refresh. Cookie sessions are updated by the engine automatically. With the SDK, use onTokenRefreshed.

Device details

At login, the engine records which device and app the session belongs to, so users can recognize their sessions. It’s returned as the metadata object on every session:

"metadata": { "label": "Chrome 131 on Android", "browser": "Chrome", "browserVersion": "131", "os": "Android", "device": "Mobile", "client": "My App", "userAgent": "Mozilla/5.0 (Linux; Android 14; Pixel 8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Mobile Safari/537.36" }
FieldSourceDescription
labelUser-AgentReadable summary, for example Chrome 131 on Android.
browserUser-AgentBrowser or HTTP client
browserVersionUser-AgentMajor version for browsers, full version for HTTP clients.
osUser-AgentOperating system, see the values below.
deviceUser-AgentDesktop, Mobile, Tablet or Other (non-browser clients).
clientX-Bsh-ClientName of the app that logged in clientName.
userAgentUser-AgentThe raw header, cut to 512 characters.
FieldPossible values
browserEdge, Opera, Samsung Internet, Firefox, Chrome, Safari, Postman, curl, axios, node-fetch, Java, Python
osWindows, iOS, Android, ChromeOS, macOS, Linux
deviceDesktop, Mobile, Tablet, Other

The SDK exports these lists as BshSessionMetaData.

The client IP address is not stored with the session.

Managing sessions

From the dashboard

BSH_ADMIN users see the sessions of every user under Security → Auth Sessions, with the device, owner, status and dates of each session. Active sessions can be revoked from the actions column, except the one you are using.

Auth Sessions

Every user can manage their own sessions from their Profile. The session in use is pinned at the top as This device. Other active sessions can be revoked one by one, or all at once with Sign out other sessions.

Profile Sessions

From the API or the SDK

Last updated on