Security and access
Sessions and two-factor authentication
Enroll TOTP, inspect active sessions and understand what session revocation actually enforces.
Enroll an authenticator in two steps
Identity exposes authenticated TOTP enrollment endpoints beneath /api/v1/identity. POST /2fa/enroll creates or rotates the user's shared secret and returns enrollment information including an otpauth:// URI. Display it only in the account's enrollment flow.
Enrollment does not enable two-factor authentication by itself. POST /2fa/verify verifies the six-digit authenticator code and enables it on success. After activation, the token-issue contract accepts the required code in twoFactorCode. The module also exposes a disable operation; follow its existing command and validator rather than removing the setting directly from the database.
Test the full sequence: request enrollment, scan or enter the secret, confirm a current code, sign out, and sign back in with the second factor. A rendered QR code alone is not a successful enrollment test.
Understand the recorded session
At token issuance, Identity attempts to create UserSession with user, refresh-token fingerprint, IP, user agent, expiry and parsed client details. SessionService lists non-revoked, unexpired sessions in descending last-activity order for the self-service view.
The service checks the tenant before querying. A self-service request cannot list another user's sessions by substituting an identifier. Separate administrator endpoints support user or tenant-wide inspection and carry their own permissions.
Use the existing session routes
Route beneath /api/v1/identity |
Purpose |
|---|---|
GET /sessions/me |
List the caller's active sessions |
DELETE /sessions/{sessionId} |
Revoke a session owned by the caller |
These routes require the corresponding IdentityPermissions.Sessions permissions. Revocation can return 204 when successful or 404 when the target is not found by that operation. Administrative revocation is a separate API path; it must not be substituted for a self-service request merely because the UI already knows a user ID.
The tenant-wide query limits page size: values outside 1–200 fall back to 50. Use pagination and the server's total count rather than expecting one call to return every session.
Understand revocation and refresh
Revocation marks the session and records who revoked it and why. The refresh handler validates session state and rejects refresh for a revoked session. Rotation updates the stored refresh-token fingerprint and expiry for the existing session.
Do not promise that revoking an ordinary session instantly invalidates every previously issued access JWT. The code explicitly checks session validity on refresh, while the JWT validation hook has a separate live revocation check for impersonation grants. Design account-security expectations around the actual token lifetime and client sign-out behavior.
Session creation is best-effort in the token-issue handler. If it fails, sign-in can still succeed and a warning is logged. Investigate migrations and session storage if users consistently authenticate without appearing in the session view.
Verify across two clients
Sign in twice in separate browser profiles, identify the two sessions, revoke one and attempt refresh from that profile. Confirm the other intended session continues according to the operation selected. Repeat with a user lacking session-revocation permission and with another tenant's session identifier.
Check TOTP with a wrong code and a correct current code, and confirm enrollment is not activated before verification. Use synthetic accounts and avoid recording shared secrets or token values in test reports. See authentication for token contracts and identity for account administration.