Skip to main content

Browser app sessions with AuthCrunch

Choose the session protocol from the public browser topology. React and other single-page apps can use the same server contracts. The release provides portal APIs, handlers and a native portal script. The application supplies its own session adapter and state management.

DeploymentSession owner and integration
Portal, app and API share scheme, host and portThe portal owns the HttpOnly cookies. The app can coordinate portal renewal and load its verified app identity from a same-origin endpoint.
App and portal run at different subdomains or portsThe browser sees different origins. Use trusted same-origin routing or use OIDC. Sharing cookie Domain does not satisfy the refresh origin check.
A backend for frontend (BFF) owns an OIDC sessionThe BFF owns tokens, rotation, revocation and the app cookie. The browser asks the BFF for verified app-session metadata.
A browser app is an OIDC public clientRegister an exact HTTPS redirect URI, token_endpoint_auth_method: none and S256 PKCE. Use a maintained OIDC client and the registered browser origin.
The app uses direct-policy OAuthIts opaque gatekeeper session follows the policy's own lifecycle.

For downstream OIDC, select an eligible built-in local realm. The provider returns opaque OIDC access tokens and separately signed ID tokens. An application still needs a server-side authorization policy suitable for its credentials. Refresh grants require the provider's registration and consent contract for offline_access. Keep confidential client secrets on the server.

Verify an app session​

Configure the canonical public origin and portal mount, such as /auth or /company/auth. For the root mount use an empty URL prefix when joining paths. Keep the original path through Caddy. Use trusted HTTPS in development so origin, cookie and Web Lock behavior match production.

For a portal-cookie session, first send GET <mount>/whoami?probe=true with exact Accept: application/json, same-origin credentials and no cache. Require verified JSON with authenticated: true and the access expiry exp. A renewable login also has a nonempty sid identifying the refresh family. Access-only logins cannot create a refresh family by calling the refresh API. Match the refresh configuration and its eligible login methods.

Load an app-owned session response with the stable account identifier and current permissions that your server verifies. Include the verified family when the application uses it for coordination. A stable account identifier uses the immutable user identity and its trusted issuer, realm or tenant. Email, display name, access-token jti and refresh-family sid describe different lifetimes. A client-decoded JWT does not establish account or API authorization. Treat redirects, HTML or unexpected response shapes as protocol failures. The portal probe is separate from the app's permission checks.

Coordinate with native portal tabs​

Use one same-origin coordinator per portal mount. The native script uses the origin-scoped Web Lock and localStorage key authcrunch-session: plus the mount without a trailing slash. For root the key is just authcrunch-session:. Use the same key in a custom coordinator and combine it with a single shared in-tab request. A tab or application suffix would leave the native tab free to rotate outside the lock.

The shared journal is metadata only. Its fields are session_id, access_expires_at, session_expires_at, pending and blocked. Deadlines are Unix seconds. Verify server evidence before trusting identity, permissions or the existence of a session. Keep tokens, account data, app CSRF values and form drafts out of the journal. Unavailable Web Locks or unusable browser storage leaves custom rotation unavailable. Existing verified access can follow the app's own expiry/recovery policy.

Browser operationMethod and path
Verify accessGET <mount>/whoami?probe=true
Inspect the current familyPOST <mount>/api/refresh_session
RotatePOST <mount>/api/refresh_token
Revoke the sessionPOST <mount>/api/logout

For all three POSTs, send exactly {} with Content-Type: application/json and X-Authcrunch-Refresh: 1. Only rotation sends X-Authcrunch-Refresh-Session: EXPECTED_SID. Use same-origin credentials and no cache. Set redirect: 'error' in a custom fetch adapter. The browser supplies the origin and fetch metadata. A rotation sets replacement cookies and returns only session metadata in JSON. The inspection JSON returns the current family ID without rotating it.

Bootstrap and rotate​

  1. Acquire the shared lock, then read the journal and check verified access. Re-evaluate after waiting for other tabs. If the probe returns 401 and there is no uncertainty marker, inspect the refresh family before attempting to rotate. A read outage can be retried with a bounded policy.
  2. If the same-family journal is pending or blocked, prevent rotation. A newer access expiry in that family is insufficient to settle the old exchange. A verified different family can supersede a marker tied to a known old family. Use fresh login if the old family cannot be identified.
  3. Before posting the rotation, write pending: true under the lock for the expected family. If the write fails, stop before dispatch. Send that family in the precondition header. Hold the lock through the response body, validation and final journal write.
  4. Confirm the returned session_id and finite access and absolute session deadlines. Confirm the current app identity and permissions before releasing protected operations. A timeout, failed storage write, unexpected success body or 503 can leave the credential spent. Retain pending or blocked state. Avoid automatically replaying the rotation or using a family lookup to clear uncertainty.
  5. Treat storage changes as signals to pause, invalidate and re-verify. A background tab also needs to drop obsolete authority. Update the writer's controller directly because its own write does not emit a storage event to that document.

The native script exposes window.AuthCrunchSession.refresh(force = false) and logout(). A host choosing it as the sole renewal owner must use those methods rather than expecting a framework subscription API. The script schedules renewal about 30 seconds before the access deadline. Your app chooses whether proactive renewal should keep an idle tab active. A successful renewal extends the family idle deadline. Ordinary API traffic does not extend it, and renewal cannot extend the absolute deadline. An app-only activity timer cannot stop a native portal tab from renewing.

Keep requests and navigation bound to the account​

Start route guards after the session check resolves. Show a loading or recovery state while authority is unknown. Validate login return destinations against the configured origin and allowed paths. A fresh portal login begins at <mount>/login?fresh=1, using a separately validated continuation. Avoid automatic retries that send the browser between the same login and callback routes.

On a new family or account, reverify and fence in-flight work. Capture the expected account and request generation, check them again before applying a response, and suppress late results from obsolete work. Pair cancellation with those checks. Preserve valid same-account drafts through ordinary renewal, but clear account-specific state on an account switch. The server must compare the expected account with the verified cookie identity before a write. Browser cookies can change between form preflight and dispatch. Use the app's own CSRF protection and apply idempotency to eligible business writes. The portal's refresh marker header does not supply application CSRF protection.

Confirm logout and plan BFF recovery​

Use the shared lock for portal logout and require logged_out: true before announcing success. Preserve a blocked marker for the old family and clear private app state. A failed logout is unconfirmed and can offer an explicit retry. Navigating to a GET confirmation page does not prove revocation. Portal, application and upstream provider logout have distinct scopes.

For a BFF, serialize OIDC rotation and token-dependent operations by its own session. Persist the app-cookie mapping, provider credentials, deadlines, pending and revocation state under the BFF's authority. Use transactional ownership if multiple workers can operate on one session. Write pending state before dispatch and persist replacements before reporting success. A process restart cannot unspend a remotely rotated credential. After a lost response, fresh authentication may be required. AuthCrunch runtime-state persistence and the BFF's persistence solve different parts of restart.

Test a native portal tab alongside an app tab, expiration during use, an account switch mid-request, a lost refresh response, same-account draft preservation, and logout observed by a background tab. Review the versioned React coordination guidance for controller, request and test integration patterns.

Agentic Prompts​

Choose a session topology
Read the upstream root AGENTS.md files first:
https://github.com/greenpau/caddy-security/blob/v1.8.1/AGENTS.md
https://github.com/greenpau/go-authcrunch/blob/v1.7.1/AGENTS.md
Read applicable scoped AGENTS.md files, then the relevant skills and linked
implementation and tests under:
https://github.com/greenpau/caddy-security/tree/v1.8.1/.codex/skills
https://github.com/greenpau/go-authcrunch/tree/v1.7.1/.codex/skills
Distinguish main from the versions I deploy. Resolve disagreements using
versioned code and tests. Ask me to paste an inaccessible source. Use synthetic
or redacted inputs and flag unverified behavior.

Secondary context: https://docs.authcrunch.com/docs/authenticate/webapps/browser-sessions

Compare a same-origin portal app, an OIDC public client and an OIDC BFF for my deployment. Explain which component controls tokens, refresh, app permissions and logout.
Coordinate with a native portal tab
Read the upstream root AGENTS.md files first:
https://github.com/greenpau/caddy-security/blob/v1.8.1/AGENTS.md
https://github.com/greenpau/go-authcrunch/blob/v1.7.1/AGENTS.md
Read applicable scoped AGENTS.md files, then the relevant skills and linked
implementation and tests under:
https://github.com/greenpau/caddy-security/tree/v1.8.1/.codex/skills
https://github.com/greenpau/go-authcrunch/tree/v1.7.1/.codex/skills
Distinguish main from the versions I deploy. Resolve disagreements using
versioned code and tests. Ask me to paste an inaccessible source. Use synthetic
or redacted inputs and flag unverified behavior.

Secondary context: https://docs.authcrunch.com/docs/authenticate/webapps/browser-sessions

Walk through two tabs reaching access expiry and one tab rotating. Show the role of the shared lock, journal and exact session precondition.
Recover after an uncertain exchange
Read the upstream root AGENTS.md files first:
https://github.com/greenpau/caddy-security/blob/v1.8.1/AGENTS.md
https://github.com/greenpau/go-authcrunch/blob/v1.7.1/AGENTS.md
Read applicable scoped AGENTS.md files, then the relevant skills and linked
implementation and tests under:
https://github.com/greenpau/caddy-security/tree/v1.8.1/.codex/skills
https://github.com/greenpau/go-authcrunch/tree/v1.7.1/.codex/skills
Distinguish main from the versions I deploy. Resolve disagreements using
versioned code and tests. Ask me to paste an inaccessible source. Use synthetic
or redacted inputs and flag unverified behavior.

Secondary context: https://docs.authcrunch.com/docs/authenticate/webapps/browser-sessions

Compare safe read failure, possibly dispatched rotation and a verified different family after login. Describe when fresh authentication is needed.
Fence stale account work
Read the upstream root AGENTS.md files first:
https://github.com/greenpau/caddy-security/blob/v1.8.1/AGENTS.md
https://github.com/greenpau/go-authcrunch/blob/v1.7.1/AGENTS.md
Read applicable scoped AGENTS.md files, then the relevant skills and linked
implementation and tests under:
https://github.com/greenpau/caddy-security/tree/v1.8.1/.codex/skills
https://github.com/greenpau/go-authcrunch/tree/v1.7.1/.codex/skills
Distinguish main from the versions I deploy. Resolve disagreements using
versioned code and tests. Ask me to paste an inaccessible source. Use synthetic
or redacted inputs and flag unverified behavior.

Secondary context: https://docs.authcrunch.com/docs/authenticate/webapps/browser-sessions

Trace a form that was opened under one user and then submitted after a switch to another. Identify checks before dispatch, before server mutation, and when applying the response.
Verify sign-out and restart
Read the upstream root AGENTS.md files first:
https://github.com/greenpau/caddy-security/blob/v1.8.1/AGENTS.md
https://github.com/greenpau/go-authcrunch/blob/v1.7.1/AGENTS.md
Read applicable scoped AGENTS.md files, then the relevant skills and linked
implementation and tests under:
https://github.com/greenpau/caddy-security/tree/v1.8.1/.codex/skills
https://github.com/greenpau/go-authcrunch/tree/v1.7.1/.codex/skills
Distinguish main from the versions I deploy. Resolve disagreements using
versioned code and tests. Ask me to paste an inaccessible source. Use synthetic
or redacted inputs and flag unverified behavior.

Secondary context: https://docs.authcrunch.com/docs/authenticate/webapps/browser-sessions

Design a test that verifies logout across tabs and a separate BFF crash during rotation. Distinguish confirmation, revocation scope and durable state ownership.

Source Code References​