Authentication and sessions
On this page
Password login protocol
AdminAuthController uses /api/auth/[action]. A host client performs these steps:
GET /api/auth/GetLoginPasswordPublicKeyto obtainkeyId, an SPKI public key,nonce, algorithm and UTC expiry.- Encrypt UTF-8 JSON
{ "password": "...", "nonce": "..." }with the returned key usingRSA-OAEP-SHA256, then Base64-encode the ciphertext. POST /api/auth/Loginwithname, the encryptedpasswordandpasswordKeyId.- 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 field | Use in the login request |
|---|---|
keyId | Copy unchanged into passwordKeyId |
publicKey | Encrypt this attempt’s password payload; it is not itself a password |
nonce | Include unchanged alongside password in the encrypted JSON |
algorithm | Require RSA-OAEP-SHA256; do not substitute PKCS#1 v1.5 |
expiresAt | Decide 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 / value | Client responsibility |
|---|---|
Authorization: Bearer ... | Attach the access token to administration requests |
X-Refreshed-Token | Accept renewed access tokens from responses |
POST /api/auth/RefreshToken | Explicit refresh with { "refreshToken": "..." }, or the same-origin refresh cookie |
POST /api/auth/Me | Restore the current authentication snapshot |
Logout / LogoutAll | Revoke 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
| Stage | First checks |
|---|---|
| Challenge returns 404 | Use GET and /api/auth/GetLoginPasswordPublicKey; register the controller in the active RPC store |
| Browser cannot encrypt | Secure context, available crypto.subtle, Base64-decoded SPKI and RSA-OAEP / SHA-256 |
| Challenge succeeds but login fails | Match keyId, public key and nonce; encrypt UTF-8 JSON; obtain a new challenge before retrying |
| Login succeeds but later requests return 401 | Bearer header, expiry, matching endpoint and realm, and a session that has not been revoked |
| Refresh occasionally signs the user out | Serialize refresh per login and prevent late responses from replacing newer credentials |
| Reload loses the login | Host 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.