Skip to Content
TAdminAuthentication and sessions

Authentication and sessions

On this page

Password login protocol

AdminAuthController uses /api/auth/[action]. A host client performs these steps:

  1. GET /api/auth/GetLoginPasswordPublicKey to obtain keyId, an SPKI public key, nonce, algorithm and UTC expiry.
  2. Encrypt UTF-8 JSON { "password": "...", "nonce": "..." } with the returned key using RSA-OAEP-SHA256, then Base64-encode the ciphertext.
  3. POST /api/auth/Login with name, the encrypted password and passwordKeyId.
  4. Persist the returned session credentials and apply the permission and menu snapshot.

Challenges expire after two minutes and can be consumed once. Obtain a new challenge when retrying login. Deploy over HTTPS.

Successful responses use the result envelope, placing challenge fields inside data. publicKey is Base64-encoded SPKI binary, not PEM text. Decode Base64 before importing it in the browser with spki, RSA-OAEP and SHA-256.

Challenge fieldUse in the login request
keyIdCopy unchanged into passwordKeyId
publicKeyEncrypt this attempt’s password payload; it is not itself a password
nonceInclude unchanged alongside password in the encrypted JSON
algorithmRequire RSA-OAEP-SHA256; do not substitute PKCS#1 v1.5
expiresAtDecide when to obtain a fresh challenge; expired or consumed challenges require starting again

The login body has this structure. Replace password with the Base64 ciphertext produced above:

{ "name": "admin", "password": "<Base64 RSA-OAEP ciphertext>", "passwordKeyId": "<keyId from the same challenge>" }

Client implementation: samples/TAdmin.Sample/web/src/api/session.ts.

Tokens and renewal

Entry / valueClient responsibility
Authorization: Bearer ...Attach the access token to administration requests
X-Refreshed-TokenAccept renewed access tokens from responses
POST /api/auth/RefreshTokenExplicit refresh with { "refreshToken": "..." }, or the same-origin refresh cookie
POST /api/auth/MeRestore the current authentication snapshot
Logout / LogoutAllRevoke the current session / every session

LoginOutput includes AccessToken, RefreshToken, SessionId, JwtId, expiry, user, permissions and menus. HttpOnly refresh cookies are separated by administration realm. Credential persistence belongs to the host.

Direct cross-origin access requires CORS, cookie-credential and refresh-token configuration.

On page load, restore credentials, refresh if needed, then call Me for the permission snapshot. Save renewed credentials. Logout clears credentials and snapshots and invalidates the old request scope.

Concurrent refresh and request scope

Serialize refresh requests belonging to the same login. Normal token rotation preserves login identity and page drafts. Access-token text is not a stable login identifier.

The predicate returned by captureRequestScope must capture the endpoint, tenant / realm and login generation. Logout, endpoint or realm changes, and a new login invalidate old predicates. Normal renewal leaves them valid. Late responses from an expired scope must not overwrite the new login’s state.

The host synchronizes credentials across tabs; the sample uses Web Locks and storage events.

Diagnose by failure stage

StageFirst checks
Challenge returns 404Use GET and /api/auth/GetLoginPasswordPublicKey; register the controller in the active RPC store
Browser cannot encryptSecure context, available crypto.subtle, Base64-decoded SPKI and RSA-OAEP / SHA-256
Challenge succeeds but login failsMatch keyId, public key and nonce; encrypt UTF-8 JSON; obtain a new challenge before retrying
Login succeeds but later requests return 401Bearer header, expiry, matching endpoint and realm, and a session that has not been revoked
Refresh occasionally signs the user outSerialize refresh per login and prevent late responses from replacing newer credentials
Reload loses the loginHost persistence and restore flow, cookie / explicit refresh-token policy, and the Me response

Handle HTTP status alongside envelope code and msg. A 403 with msg equal to PasswordChangeRequired requires completing a password change; see the troubleshooting reference.

Session operations

Password changes, explicit revocation and logout-all affect session validity. See Vue integration for request-scope cancellation.