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).

Legend

GET ReadPOST Create / ActionPUT UpdateDELETE Delete

Authentication login: 10 req/15min · register: 5 req/15min · forgot-password: 5 req/15min

MethodPathDescriptionAuth
POST/api/auth/registerCreate a new user account. Accepts email, password, firstName, lastName. Validates password strength (zxcvbn), checks HIBP breach database, hashes with Argon2id.No
POST/api/auth/loginAuthenticate with email and password. Returns user data or 2FA challenge. Sets auth_token cookie on success. Rate limited: 10 requests per 15 minutes.No
POST/api/auth/logoutEnd the current session. Clears auth_token cookie and deactivates the session in the database.Yes
POST/api/auth/forgot-passwordSend a password reset email. Accepts email address. Token is SHA-256 hashed before storage. Rate limited: 5 per 15 minutes.No
POST/api/auth/reset-passwordReset password using a valid token. Validates new password strength, hashes with Argon2id.No
POST/api/auth/validate-reset-tokenCheck if a password reset token is still valid (not expired, not used).No
POST/api/auth/verify-emailVerify email address using a token from the verification email.No
POST/api/auth/resend-verificationResend the email verification link.Yes
GET/api/auth/meGet the currently authenticated user's basic info (id, email, name, avatar, role).Yes

Social Login (OAuth)

MethodPathDescriptionAuth
POST/api/auth/oauth/initiateInitiate social login. Accepts provider ("google" or "github"). Generates CSRF state + PKCE, returns authorization URL.No
GET/api/auth/oauth/callbackOAuth callback handler. Verifies state, exchanges code for tokens, creates or links user account.No

WebAuthn / Passkeys

MethodPathDescriptionAuth
POST/api/auth/passkey/register-optionsGet WebAuthn registration options. Generates a challenge stored in user metadata.Yes
POST/api/auth/passkey/register-verifyVerify and save a new passkey registration.Yes
POST/api/auth/passkey/authenticate-optionsGet WebAuthn authentication options (for login). Supports Conditional UI.No
POST/api/auth/passkey/authenticate-verifyVerify passkey assertion and create a session.No

Two-Factor Authentication 10 req/15min

MethodPathDescriptionAuth
POST/api/auth/2fa/setupInitialize 2FA setup. Accepts method ("totp", "email", "sms"). For TOTP, returns QR code URI and encrypted secret.Yes
POST/api/auth/2fa/verifyVerify a 2FA code. Used both during setup confirmation and login verification. Accepts userId, code, and method.Partial
POST/api/auth/2fa/disableDisable a specific 2FA method. Requires current password for verification.Yes
POST/api/auth/2fa/send-codeSend an OTP code via email or SMS. Used during login when the user's default 2FA method is email or SMS. Rate limited: 10 per 15 minutes.Partial
POST/api/auth/2fa/set-defaultSet the default 2FA method when multiple are enabled.Yes

User 100 req/15min

MethodPathDescriptionAuth
GET/api/user/profileGet 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/profileUpdate user profile fields. Validates username format, date of birth, website URL, etc.Yes
GET/api/user/securityGet security overview: 2FA status, enabled methods, passkey count, email verification status.Yes
POST/api/user/passwordChange password. Requires current password. Validates new password strength. Invalidates all other sessions.Yes
GET/api/user/sessionsList all active sessions for the current user (IP, user agent, device type, last activity, current session indicator).Yes
POST/api/user/sessions/revoke-allRevoke all sessions except the current one.Yes
GET/api/user/passkeysList registered passkeys (credential ID, device name, created date, last used).Yes
DELETE/api/user/passkeysDelete a passkey by credential ID.Yes
GET/api/user/activityGet the user's activity log (login, logout, password changes, 2FA events, etc.).Yes
GET/api/user/connected-servicesList connected OAuth providers (Google, GitHub) with connection status.Yes
GET/api/user/authorized-appsList OAuth applications the user has authorized (granted consent to).Yes
POST/api/user/email/request-changeRequest an email address change. Sends verification to the new email.Yes
POST/api/user/email/verify-changeConfirm the email change using the verification token.Yes
GET/api/user/preferencesGet user preferences (language, timezone, date format, notification settings).Yes
PUT/api/user/preferencesUpdate user preferences.Yes
POST/api/user/avatarUpload a user avatar image.Yes
GET/api/user/exportExport all user data (GDPR data portability).Yes
DELETE/api/user/deletePermanently delete the user account and all associated data. Requires password confirmation.Yes

Developer Console (OAuth Clients)

MethodPathDescriptionAuth
GET/api/user/oauth-clientsList OAuth clients created by the current user (max 10).Yes
POST/api/user/oauth-clientsRegister 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: 100 req/15min · token: 100 req/15min

MethodPathDescriptionAuth
GET/api/oauth/authorizeAuthorization 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/consentHandle user consent decision (approve or deny). Stores consent record and redirects with authorization code.Session
POST/api/oauth/tokenToken endpoint. Supports grant types: authorization_code, refresh_token, client_credentials, device_code. Returns access_token, id_token, refresh_token.Client
GET/api/oauth/userinfoReturns OIDC claims for the authenticated user based on granted scopes. Requires Bearer token.Bearer
POST/api/oauth/introspectToken introspection (RFC 7662). Returns active status and token metadata. Requires client authentication.Client
POST/api/oauth/revokeToken revocation (RFC 7009). Revoke access or refresh tokens. Always returns 200.Client
GET/api/oauth/end-sessionRP-Initiated Logout. Clears session, triggers back-channel logout, redirects to post_logout_redirect_uri.No
POST/api/oauth/deviceDevice authorization (RFC 8628). Returns device_code, user_code, and verification URI.No
POST/api/oauth/device/verifyVerify a device user code (user-facing endpoint for approving device login).Session
POST/api/oauth/registerDynamic client registration (RFC 7591). Register a new OAuth client programmatically.No
GET/api/oauth/client-infoGet client information for the consent page (includes current user for personalized scope previews).Session

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).

MethodPathDescriptionAuth
GET/api/scim/v2/UsersList users with optional filtering, pagination (startIndex, count).Bearer
POST/api/scim/v2/UsersCreate 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]Delete a user via SCIM.Bearer
GET/api/scim/v2/ServiceProviderConfigSCIM service provider configuration (supported features, auth schemes).No
GET/api/scim/v2/SchemasList supported SCIM schemas.No
GET/api/scim/v2/ResourceTypesList supported SCIM resource types.No

Administration 100 req/15min

Admin endpoints require the user to have the admin or moderator role. Role-based permissions are enforced via the verifyAdmin() helper.

MethodPathDescriptionRole
GET/api/admin/usersList all users with search, pagination, and filtering by role/status.Admin
GET/api/admin/users/[id]Get detailed information about a specific user.Admin
PUT/api/admin/users/[id]Update a user (change role, lock/unlock account, modify profile).Admin
DELETE/api/admin/users/[id]Delete a user account and all associated data.Admin
GET/api/admin/sessionsList all active sessions across all users.Admin
GET/api/admin/activitySystem-wide activity log with search and filtering.Admin
GET/api/admin/rolesList all roles with their permissions.Admin
POST/api/admin/rolesCreate a new role with custom permissions.Admin
GET/api/admin/settingsGet system settings (email, security, etc.).Admin
PUT/api/admin/settingsUpdate system settings.Admin
GET/api/admin/statsDashboard statistics (total users, active sessions, registrations, etc.).Admin
GET/api/admin/analyticsDetailed analytics data (user growth, login trends, 2FA adoption, etc.).Admin
GET/api/admin/oauth-clientsList all OAuth clients (across all users).Admin
POST/api/admin/oauth-clientsCreate an OAuth client (admin can create first-party clients).Admin
PUT/api/admin/oauth-clients/[id]Update any OAuth client (including first-party flag, active status).Admin
DELETE/api/admin/oauth-clients/[id]Delete an OAuth client.Admin
POST/api/admin/oidc-keysRotate the OIDC RS256 keypair. Generates a new keypair and encrypts the private key.Admin
POST/api/admin/impersonateStart impersonating a user. Sets a special impersonation cookie alongside the admin's session.Admin
POST/api/admin/impersonate/stopStop impersonating and return to admin view.Admin

Webhooks

MethodPathDescriptionRole
GET/api/admin/webhooksList all configured webhooks.Admin
POST/api/admin/webhooksCreate a webhook. Specify URL, secret, and subscribed events (user.created, user.updated, user.deleted, login.success, login.failed, etc.).Admin
GET/api/admin/webhooks/[id]Get webhook details including recent delivery history.Admin
PUT/api/admin/webhooks/[id]Update a webhook (URL, events, active status).Admin
DELETE/api/admin/webhooks/[id]Delete a webhook and all delivery records.Admin
POST/api/admin/webhooks/[id]/testSend a test event to the webhook URL to verify connectivity.Admin

Well-Known Endpoints

MethodPathDescriptionAuth
GET/.well-known/openid-configurationOpenID Connect Discovery document. Returns issuer, endpoints, supported scopes, response types, grant types, and signing algorithms.No
GET/.well-known/jwks.jsonJSON Web Key Set. Returns the RS256 public key used for ID token signature verification.No

Other Endpoints

MethodPathDescriptionAuth
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. The limits are applied per IP address with a 15-minute sliding window:

Endpoint PatternLimitWindow
/api/auth/login10 requests15 minutes
/api/auth/register5 requests15 minutes
/api/auth/forgot-password5 requests15 minutes
/api/auth/2fa/*10 requests15 minutes
All other /api/*100 requests15 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