Skip to Content
Referência da APIAPI de Sessões

Sessions API

The Sessions API provides visibility and control over user sessions across the tenant. Administrators can list active sessions, inspect session details, revoke individual sessions or all sessions for a user, and configure session lifetime policies.

A session is created when a user successfully authenticates (via password, magic link, social login, or SSO). Each session tracks the device, IP address, last activity time, and authentication method used. Sessions remain active until they expire, are revoked by an administrator, or the user logs out.

Session Management

List Sessions

GET/api/sessionsRequires: manage:sessions

List sessions across the tenant. Supports filtering by user ID and active/inactive status. Returns session metadata including device information, IP address, and authentication method. Sessions are ordered by last activity time descending.

Query parameters

ParameterTypeDescription
pageintegerPage number (default: 1)
limitintegerItems per page (default: 20, max: 100)
userIdstringFilter sessions for a specific user
activebooleantrue for active sessions only, false for expired/revoked only

Success response

{ "ok": true, "data": { "data": [ { "id": "sess_abc123", "userId": "usr_xyz789", "userEmail": "[email protected]", "userName": "Alice Smith", "ipAddress": "203.0.113.50", "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36", "device": "Chrome on macOS", "authMethod": "password", "isActive": true, "createdAt": "2025-02-18T08:00:00Z", "lastActivityAt": "2025-02-18T09:45:00Z", "expiresAt": "2025-02-19T08:00:00Z" }, { "id": "sess_def456", "userId": "usr_abc123", "userEmail": "[email protected]", "userName": "Bob Jones", "ipAddress": "198.51.100.42", "userAgent": "Mozilla/5.0 (iPhone; CPU iPhone OS 17_3 like Mac OS X) AppleWebKit/605.1.15", "device": "Safari on iOS", "authMethod": "magic_link", "isActive": true, "createdAt": "2025-02-18T07:30:00Z", "lastActivityAt": "2025-02-18T09:30:00Z", "expiresAt": "2025-02-19T07:30:00Z" }, { "id": "sess_ghi789", "userId": "usr_xyz789", "userEmail": "[email protected]", "userName": "Alice Smith", "ipAddress": "203.0.113.51", "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)", "device": "Edge on Windows", "authMethod": "sso", "isActive": false, "revokedAt": "2025-02-17T16:00:00Z", "revokedBy": "usr_admin001", "createdAt": "2025-02-17T08:00:00Z", "lastActivityAt": "2025-02-17T15:55:00Z", "expiresAt": "2025-02-18T08:00:00Z" } ], "pagination": { "page": 1, "limit": 20, "total": 156, "totalPages": 8 } } }

Authentication methods: password, magic_link, social, sso, device_code, m2m.

Get Session

GET/api/sessions/[id]Requires: manage:sessions

Retrieve detailed information about a specific session, including the full user agent string, authentication context, and revocation details if the session has been revoked.

Success response

{ "ok": true, "data": { "id": "sess_abc123", "userId": "usr_xyz789", "userEmail": "[email protected]", "userName": "Alice Smith", "ipAddress": "203.0.113.50", "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36", "device": "Chrome on macOS", "authMethod": "password", "isActive": true, "mfaVerified": true, "mfaMethod": "totp", "acr": "urn:auris:mfa", "amr": ["pwd", "otp"], "createdAt": "2025-02-18T08:00:00Z", "lastActivityAt": "2025-02-18T09:45:00Z", "expiresAt": "2025-02-19T08:00:00Z" } }
FieldDescription
mfaVerifiedWhether 2FA was completed for this session
mfaMethodThe 2FA method used (totp, sms, webauthn, or null)
acrAuthentication Context Class Reference (OIDC claim)
amrAuthentication Methods Reference array (OIDC claim)

Error codes

CodeHTTPDescription
NOT_FOUND404Session does not exist or belongs to a different tenant

Revoke Session

DELETE/api/sessions/[id]Requires: manage:sessions

Revoke a specific session. The associated refresh token is immediately invalidated. The access token continues to be valid until it expires naturally (JWTs are stateless). For immediate lockout, combine session revocation with short access token lifetimes.

Access tokens are JWTs and cannot be individually revoked without a blocklist. Auris relies on short access token lifetimes (default 15 minutes) for security. When a session is revoked, the refresh token is invalidated, so the user cannot obtain a new access token after the current one expires.

Success response

{ "ok": true, "data": { "revoked": true, "sessionId": "sess_abc123" } }

Error codes

CodeHTTPDescription
NOT_FOUND404Session does not exist
ALREADY_REVOKED400Session has already been revoked

Revoke All User Sessions

POST/api/sessions/revoke-allRequires: manage:sessions

Revoke all active sessions for a specific user. This is useful when an account may be compromised or when an administrator needs to force a user to re-authenticate on all devices. All associated refresh tokens are immediately invalidated.

Request body

{ "userId": "usr_xyz789" }

Success response

{ "ok": true, "data": { "revoked": true, "sessionsRevoked": 3, "userId": "usr_xyz789" } }

The sessionsRevoked count indicates how many active sessions were terminated.

Error codes

CodeHTTPDescription
VALIDATION_ERROR400Missing userId field
NOT_FOUND404User does not exist in this tenant
NO_ACTIVE_SESSIONS400User has no active sessions to revoke

Revoking all sessions logs the user out of every device and browser. They will need to re-authenticate on each one. Consider notifying the user via email when performing this action.

Session Statistics

GET/api/sessions/statsRequires: manage:sessions

Get aggregate session statistics for the tenant. Useful for monitoring active users and identifying trends.

Success response

{ "ok": true, "data": { "activeSessions": 156, "uniqueUsers": 89, "last24Hours": { "newSessions": 42, "expiredSessions": 31, "revokedSessions": 3 }, "byAuthMethod": { "password": 98, "magic_link": 23, "social": 25, "sso": 10 }, "byDevice": { "desktop": 87, "mobile": 52, "tablet": 12, "unknown": 5 } } }

Session Policies

Session policies control the lifetime of sessions and tokens across the tenant. These settings apply to all users unless overridden by application-specific configuration.

Get Security Settings

GET/api/settings/securityRequires: manage:security_settings

Retrieve the current session and security policy settings for the tenant.

Success response

{ "ok": true, "data": { "sessionMaxLifetime": 86400, "sessionIdleTimeout": 3600, "refreshTokenExpiry": 604800, "accessTokenExpiry": 900, "maxConcurrentSessions": 5, "requireMfaForAdmin": true, "passwordMinLength": 8, "passwordRequireUppercase": true, "passwordRequireLowercase": true, "passwordRequireNumbers": true, "passwordRequireSpecial": false, "passwordHistoryCount": 5, "lockoutThreshold": 5, "lockoutDuration": 900, "updatedAt": "2025-02-10T14:00:00Z" } }

Session and token settings

FieldTypeDefaultDescription
sessionMaxLifetimeinteger86400 (24h)Maximum session duration in seconds, regardless of activity
sessionIdleTimeoutinteger3600 (1h)Session expires after this many seconds of inactivity
refreshTokenExpiryinteger604800 (7d)Refresh token lifetime in seconds
accessTokenExpiryinteger900 (15m)Access token lifetime in seconds
maxConcurrentSessionsinteger5Maximum active sessions per user (0 = unlimited)

MFA settings

FieldTypeDefaultDescription
requireMfaForAdminbooleantrueRequire 2FA for users with admin roles

Password policy settings

FieldTypeDefaultDescription
passwordMinLengthinteger8Minimum password length
passwordRequireUppercasebooleantrueRequire at least one uppercase letter
passwordRequireLowercasebooleantrueRequire at least one lowercase letter
passwordRequireNumbersbooleantrueRequire at least one digit
passwordRequireSpecialbooleanfalseRequire at least one special character
passwordHistoryCountinteger5Number of previous passwords to check against (0 = disabled)

Lockout settings

FieldTypeDefaultDescription
lockoutThresholdinteger5Number of failed login attempts before lockout
lockoutDurationinteger900 (15m)Lockout duration in seconds

Update Security Settings

PUT/api/settings/securityRequires: manage:security_settings

Update session and security policy settings. All fields are optional — only provided fields are updated. Changes take effect for new sessions immediately. Existing sessions are not retroactively affected (they continue with their original expiry times).

Request body

{ "sessionMaxLifetime": 43200, "accessTokenExpiry": 600, "maxConcurrentSessions": 3, "requireMfaForAdmin": true, "passwordMinLength": 12, "lockoutThreshold": 3, "lockoutDuration": 1800 }

Success response

{ "ok": true, "data": { "sessionMaxLifetime": 43200, "sessionIdleTimeout": 3600, "refreshTokenExpiry": 604800, "accessTokenExpiry": 600, "maxConcurrentSessions": 3, "requireMfaForAdmin": true, "passwordMinLength": 12, "passwordRequireUppercase": true, "passwordRequireLowercase": true, "passwordRequireNumbers": true, "passwordRequireSpecial": false, "passwordHistoryCount": 5, "lockoutThreshold": 3, "lockoutDuration": 1800, "updatedAt": "2025-02-18T11:00:00Z" } }

Error codes

CodeHTTPDescription
VALIDATION_ERROR400Invalid value (e.g., negative number, accessTokenExpiry > sessionMaxLifetime)

Validation rules

  • accessTokenExpiry must be between 60 (1 minute) and 86400 (24 hours)
  • refreshTokenExpiry must be between 3600 (1 hour) and 2592000 (30 days)
  • sessionMaxLifetime must be >= accessTokenExpiry
  • sessionIdleTimeout must be <= sessionMaxLifetime
  • maxConcurrentSessions must be between 0 and 100
  • passwordMinLength must be between 6 and 128
  • lockoutThreshold must be between 1 and 100
  • lockoutDuration must be between 60 (1 minute) and 86400 (24 hours)

Setting very short access token lifetimes (under 5 minutes) increases the frequency of token refresh requests. Setting very long lifetimes reduces security. The recommended range is 5 to 30 minutes.

Concurrent Session Enforcement

When maxConcurrentSessions is set to a non-zero value, Auris enforces a limit on the number of active sessions per user. When a new session is created and the user already has the maximum number of sessions:

  1. The oldest session (by createdAt) is automatically revoked.
  2. The new session is created normally.
  3. The user receives a notification that an older session was terminated (if in-app notifications are enabled).

This behavior ensures that users are never prevented from logging in due to stale sessions, while still maintaining a reasonable cap on concurrent access.

Session Lifecycle

User authenticates | v Session created (isActive: true) | +--- User makes API requests ---> lastActivityAt updated | +--- Access token expires ---> User refreshes token | (refreshToken still valid) | +--- Idle timeout reached ---> Session expired | +--- Max lifetime reached ---> Session expired | +--- Admin revokes session ---> Session revoked | +--- User logs out ---> Session revoked | v Session inactive (isActive: false)

Permissions Reference

PermissionDescription
manage:sessionsList, inspect, and revoke sessions across the tenant
manage:security_settingsView and update session policies and security settings

Individual users can view and revoke their own sessions through the user profile endpoints (GET /api/user/sessions, DELETE /api/user/sessions/[id]) without needing admin permissions. The endpoints documented on this page are for tenant-wide administration.