API Reference
Complete reference for all UniAuth REST API endpoints. All endpoints are prefixed with /api unless noted otherwise. Authentication is via HTTP-only cookies (for first-party requests) or Bearer tokens (for OAuth-protected endpoints).
These examples describe UniAuth’s first-party, same-origin sign-in UI, not an integration API. Third-party apps must use hosted OAuth/OIDC Authorization Code with PKCE; they must not collect UniAuth passwords.
Legend
Authentication login: 10 req/15min · register: 20 req/15min · forgot-password: 5 req/15min
| Method | Path | Description | Auth |
|---|---|---|---|
| POST | /api/auth/register | Create a new user account. Accepts email, password, firstName, lastName. Validates password strength (zxcvbn), checks HIBP breach database, hashes with Argon2id. | No |
| POST | /api/auth/login | First-party password login: email and password, then the same credentials with twoFactorCode and optional twoFactorMethod. data.requires2FA is a challenge; data.authenticated: true confirms the session. Third-party apps use hosted OAuth/OIDC with PKCE. | No |
| POST | /api/auth/logout | End the current session. Clears auth_token cookie and deactivates the session in the database. | Yes |
| POST | /api/auth/forgot-password | Durably admit a public password-reset request. A successful 200 acknowledges queued or suppressed intake, not issuance or delivery; eligible work issues a hashed token and attempts asynchronous email dispatch. An unaccepted transport result retires the proof, while transport acceptance still does not prove inbox delivery. Invalid requests, rate limits, and unavailable intake return errors. | No |
| POST | /api/auth/reset-password | Reset password using a valid token. Validates new password strength, hashes with Argon2id. | No |
| POST | /api/auth/validate-reset-token | Check if a password reset token is still valid (not expired, not used). | No |
| POST | /api/auth/verify-email | Verify email address using a token from the verification email. | No |
| POST | /api/auth/resend-verification | Public callers can durably request verification processing without authentication; authenticated sessions request it for their current account. A public 200 acknowledges queued or suppressed intake, not eligibility, link issuance, transport acceptance, or inbox delivery. Eligible work attempts email dispatch asynchronously. | No |
| GET | /api/auth/me | Get the currently authenticated user's basic info (id, email, name, avatar, role). | Yes |
Social Login (OAuth)
| Method | Path | Description | Auth |
|---|---|---|---|
| POST | /api/auth/oauth/initiate | Initiate social login. Accepts provider ("google" or "github"). Generates CSRF state + PKCE, returns authorization URL. | No |
| GET | /api/auth/oauth/callback | OAuth callback handler. Verifies state, exchanges code for tokens, creates or links user account. | No |
WebAuthn / Passkeys
| Method | Path | Description | Auth |
|---|---|---|---|
| POST | /api/auth/passkey/register-options | Get WebAuthn registration options. Generates a challenge stored in user metadata. | Yes |
| POST | /api/auth/passkey/register-verify | Verify and save a new passkey registration. | Yes |
| POST | /api/auth/passkey/authenticate-options | Get WebAuthn authentication options (for login). Supports Conditional UI. | No |
| POST | /api/auth/passkey/authenticate-verify | Verify passkey assertion and create a session. | No |
Two-Factor Authentication 10 req/15min
| Method | Path | Description | Auth |
|---|---|---|---|
| POST | /api/auth/2fa/setup | Initialize 2FA setup. Accepts method ("totp", "email", "sms"). For TOTP, returns QR code URI and encrypted secret. | Yes |
| POST | /api/auth/2fa/verify | Confirm factor enrollment only: auth_token cookie, fresh session-bound step-up for 2fa.enable, and body {code, method}. Not a login-completion endpoint; never accepts userId as authority. | Yes |
| POST | /api/auth/2fa/disable | Disable a specific 2FA method. Requires current password for verification. | Yes |
| POST | /api/auth/2fa/send-code | Anonymous resend: {email, method}, never userId; generic success with data: null proves neither account existence nor delivery. With auth_token and step-up for 2fa.disable: signed-in factor action with detailed metadata. Rate limit: 10 per 15 minutes. | Partial |
| POST | /api/auth/2fa/set-default | Set the default 2FA method when multiple are enabled. | Yes |
User 100 req/15min
| Method | Path | Description | Auth |
|---|---|---|---|
| GET | /api/user/profile | Get the full user profile including OIDC claims (username, display_name, bio, date_of_birth, gender, company, job_title, website, location, address, locale, social_links, timezone). | Yes |
| PUT | /api/user/profile | Update user profile fields. Validates username format, date of birth, website URL, etc. | Yes |
| GET | /api/user/security | Get security overview: 2FA status, enabled methods, passkey count, email verification status. | Yes |
| POST | /api/user/password | Change password. Requires current password. Validates new password strength. Invalidates all other sessions. | Yes |
| GET | /api/user/sessions | List all active sessions for the current user (IP, user agent, device type, last activity, current session indicator). | Yes |
| POST | /api/user/sessions/revoke-all | Revoke all sessions except the current one. | Yes |
| GET | /api/user/passkeys | List registered passkeys (credential ID, device name, created date, last used). | Yes |
| DELETE | /api/user/passkeys | Delete a passkey by credential ID. | Yes |
| GET | /api/user/activity | Get the user's activity log (login, logout, password changes, 2FA events, etc.). | Yes |
| GET | /api/user/connected-services | List connected OAuth providers (Google, GitHub) with connection status. | Yes |
| GET | /api/user/authorized-apps | List OAuth applications the user has authorized (granted consent to). | Yes |
| POST | /api/user/email/request-change | Create a pending email-address change for the new address. The response reports whether the configured transport accepted the verification-message dispatch attempt; this does not prove inbox delivery. The current address remains active until a valid link completes the change. | Yes |
| POST | /api/user/email/verify-change | Confirm the email change using the verification token. | Yes |
| GET | /api/user/preferences | Get user preferences (language, timezone, date format, notification settings). | Yes |
| PUT | /api/user/preferences | Update user preferences. | Yes |
| POST | /api/user/avatar | Upload a user avatar image. | Yes |
| GET | /api/user/data-export | Download a portable, allowlisted account-data copy; the document declares its history limits and excluded categories. | Yes |
| GET | /api/user/export/api/user/data-export | Download a portable, allowlisted account-data copy; the document declares its history limits and excluded categories. | Yes |
| DELETE | /api/user/delete | Request erasure of the active user account. Its sign-in credentials are irreversibly erased; its profile data and stored account content are erased or anonymized. Some security, audit, and compliance histories are minimized. Immutable or otherwise required records may be retained under applicable legal, security, anti-abuse, and retention requirements. Short-lived protocol and security records may remain in their original form until their safety windows expire and cleanup runs; published retention periods apply where defined. Personal OAuth applications in the Developer Console are disabled and their client credentials erased; organization-owned applications remain with their organizations. Billing and transaction records may be retained under applicable requirements. Requires password confirmation. | Yes |
Developer Console (OAuth Clients)
| Method | Path | Description | Auth |
|---|---|---|---|
| GET | /api/user/oauth-clients | List OAuth clients created by the current user (max 10). | Yes |
| POST | /api/user/oauth-clients | Register a new OAuth client. Returns client_id and client_secret (shown once). | Yes |
| PUT | /api/user/oauth-clients/[id] | Update an OAuth client owned by the current user. | Yes |
| DELETE | /api/user/oauth-clients/[id] | Delete an OAuth client owned by the current user. | Yes |
OAuth2 / OIDC authorize: 20 req/15min · token: 30 req/15min
| Method | Path | Description | Auth |
|---|---|---|---|
| GET | /api/oauth/authorize | Authorization endpoint. Redirects to login (if needed) then consent screen. Requires response_type=code, client_id, redirect_uri, code_challenge, code_challenge_method=S256. | Session |
| POST | /api/oauth/authorize/consent | Handle user consent decision (approve or deny). Stores consent record and redirects with authorization code. | Session |
| POST | /api/oauth/token | Token endpoint. Grant types: authorization_code, refresh_token, client_credentials (limited Beta; confidential admin-configured clients only), urn:ietf:params:oauth:grant-type:device_code, urn:ietf:params:oauth:grant-type:token-exchange, urn:openid:params:grant-type:ciba. Returns access_token, id_token, refresh_token. | Client |
| GET | /api/oauth/userinfo | Returns OIDC claims for the authenticated user based on granted scopes. Requires Bearer token. | Bearer |
| POST | /api/oauth/introspect | Token introspection (RFC 7662). Returns active status and token metadata. Requires client authentication. | Client |
| POST | /api/oauth/revoke | Token revocation (RFC 7009). Revoke access or refresh tokens. Always returns 200. | Client |
| GET | /api/oauth/end-session | RP-Initiated Logout. An active browser session requires confirmation. After local commit, attempts back-channel notification and uses a validated return URI. Does not clear auth cookies or guarantee global logout. | No |
| POST | /api/oauth/device | Device authorization (RFC 8628). Returns device_code, user_code, verification_uri, verification_uri_complete, expires_in, interval. See device flow. | No |
| POST | /api/oauth/device/verify | Verify a device user code (user-facing endpoint for approving device login). | Session |
| POST | /api/oauth/register | Dynamic client registration (RFC 7591). Register a new OAuth client programmatically. | No |
| GET | /api/oauth/client-info | Get client information for the consent page (includes current user for personalized scope previews). | Session |
Note: Delegated organization management endpoints live under /api/org/[id]/* (e.g. members, groups, clients, domains, SSO, billing). They are scoped to a single organization, gated by the caller's org role, and derive the org from the authenticated principal — a mismatched [id] returns 404. Tier-gated features return 402 with body { "code": "upgrade_required" }.
SCIM 2.0 Provisioning 100 req/15min
SCIM (System for Cross-domain Identity Management) endpoints for automated user provisioning. Authenticated via Bearer token (SCIM token configured per OAuth client).
| Method | Path | Description | Auth |
|---|---|---|---|
| GET | /api/scim/v2/Users | List users with optional filtering, pagination (startIndex, count). | Bearer |
| POST | /api/scim/v2/Users | Create a new user via SCIM. Accepts SCIM User schema (userName, name, emails, etc.). | Bearer |
| GET | /api/scim/v2/Users/[id] | Get a specific user by ID in SCIM format. | Bearer |
| PUT | /api/scim/v2/Users/[id] | Replace a user (full update via SCIM). | Bearer |
| DELETE | /api/scim/v2/Users/[id] | SCIM DELETE removes a guest's organization membership or deactivates a managed identity. It does not erase the UniAuth account. | Bearer |
| GET | /api/scim/v2/ServiceProviderConfig | SCIM service provider configuration (supported features, auth schemes). | No |
| GET | /api/scim/v2/Schemas | List supported SCIM schemas. | No |
| GET | /api/scim/v2/ResourceTypes | List supported SCIM resource types. | No |
Well-Known Endpoints
| Method | Path | Description | Auth |
|---|---|---|---|
| GET | /.well-known/openid-configuration | OpenID Connect Discovery document. Returns issuer, endpoints, supported scopes, response types, grant types, and signing algorithms. | No |
| GET | /.well-known/jwks.json | JSON Web Key Set. Returns algorithm-neutral RSA public keys for RS256, RS384, RS512, PS256, PS384, and PS512 verification, plus an ES256 EC public key. | No |
Other Endpoints
| Method | Path | Description | Auth |
|---|---|---|---|
| GET | /api/avatar/[id] | Get a user's avatar image by user ID. Returns the image directly or a generated fallback. | No |
Rate Limiting
All API endpoints are rate-limited per IP address over a 15-minute window. The most common limits are below. Several sensitive endpoints are tighter than this table, and a few high-frequency ones (such as sign-in polling) are higher:
| Endpoint Pattern | Limit | Window |
|---|---|---|
/api/auth/login | 10 requests | 15 minutes |
/api/auth/register | 20 requests | 15 minutes |
/api/auth/forgot-password | 5 requests | 15 minutes |
/api/auth/2fa/* | 10 requests | 15 minutes |
/api/user/backup-codes | 10 requests | 15 minutes |
All other /api/* | 100 requests | 15 minutes |
When rate limited, the API returns HTTP 429 with a Retry-After header indicating when the client can retry.
Error Responses
All API errors follow a consistent JSON format:
// Standard error response
{
"success": false,
"error": "Human-readable error message"
}
// Common HTTP status codes:
// 400 — Bad request (validation error, missing fields)
// 401 — Unauthorized (not authenticated)
// 403 — Forbidden (insufficient permissions)
// 404 — Not found
// 409 — Conflict (duplicate resource)
// 423 — Locked (account lockout)
// 429 — Too many requests (rate limited)
// 500 — Internal server error