Documentation

Authentication

Core authentication endpoints for admin login, token management, and password reset flows.

Overview

Authentication Flow

The platform uses JWT-based authentication with access and refresh tokens. Access tokens are short-lived (typically 15-30 minutes) while refresh tokens have longer validity.

Token TypePurposeTypical Lifetime
Access TokenAuthenticates API requests via Bearer header15-30 minutes
Refresh TokenObtains new access tokens without re-login7-30 days
Pending TokenTemporary token during MFA verification5 minutes

Login States

The login endpoint can return different states based on user configuration.

StateResponseNext Step
Success (no MFA)Returns access_token and refresh_tokenStore tokens, redirect to dashboard
MFA RequiredReturns pending_token onlyShow MFA verification form
Invalid CredentialsReturns 401 errorShow error message

Token Storage

Tokens should be stored securely on the client side.

Storage OptionSecurityRecommendation
localStorageVulnerable to XSSUse for development only
httpOnly CookiesProtected from XSSRecommended for production
MemoryLost on page refreshUse with refresh token rotation

Login

Admin Login

POST/auth/login

Authenticates an admin user with email and password. If MFA is enabled, returns a pending_token that must be verified before access is granted.

Headers

ParameterTypeRequiredDescription
Content-TypestringYesapplication/json

Response- Login response (varies based on MFA status)

json
{
  "access_token": "eyJhbGciOiJIUzI1NiIs...",
  "refresh_token": "eyJhbGciOiJIUzI1NiIs...",
  "expires_in": 1800,
  "role": "admin"
}

Request Payload

json
{
  "email": "admin@example.com",
  "password": "securePassword123"
}

Success Response (No MFA)

json
{
  "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "expires_in": 1800,
  "role": "admin"
}

MFA Required Response

json
{
  "pending_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "mfa_required": true
}

Example Request

bash
curl -X POST "https://api.example.com/auth/login" \
  -H "Content-Type: application/json" \
  -d '{
    "email": "admin@example.com",
    "password": "securePassword123"
  }'

Error Responses

StatusCodeDescription
401invalid_credentialsEmail or password is incorrect
403account_lockedAccount locked due to too many failed attempts
403account_disabledAccount has been deactivated
429rate_limitedToo many login attempts, try again later

Token Refresh

Refresh Access Token

POST/auth/refresh

Exchanges a valid refresh token for a new access token and refresh token pair. The old refresh token is invalidated (rotation).

Headers

ParameterTypeRequiredDescription
Content-TypestringYesapplication/json

Response- New token pair

json
{
  "access_token": "eyJhbGciOiJIUzI1NiIs...",
  "refresh_token": "eyJhbGciOiJIUzI1NiIs...",
  "expires_in": 1800
}

Request Payload

json
{
  "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c3JfMTIzIiwidHlwZSI6InJlZnJlc2giLCJleHAiOjE3MDk4MjQwMDB9..."
}

Success Response

json
{
  "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c3JfMTIzIiwidHlwZSI6ImFjY2VzcyIsImV4cCI6MTcwOTgyNTgwMH0...",
  "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c3JfMTIzIiwidHlwZSI6InJlZnJlc2giLCJleHAiOjE3MTI0MTc4MDB9...",
  "expires_in": 1800
}

Example Request

bash
curl -X POST "https://api.example.com/auth/refresh" \
  -H "Content-Type: application/json" \
  -d '{
    "refresh_token": "eyJhbGciOiJIUzI1NiIs..."
  }'

Token Refresh Strategy

Best practices for implementing token refresh in your application.

StrategyDescription
Proactive RefreshRefresh before expiry (e.g., at 80% of lifetime)
Reactive RefreshRefresh on 401 response, then retry original request
Background RefreshUse a timer to refresh tokens while app is active
RotationAlways store the new refresh token after each refresh

Error Responses

StatusCodeDescription
401invalid_tokenRefresh token is invalid or malformed
401token_expiredRefresh token has expired
401token_revokedRefresh token has been revoked (logout or security event)

Logout

Admin Logout

POST/auth/logout

Invalidates the current session and revokes associated tokens. The access token and refresh token will no longer be valid.

Headers

ParameterTypeRequiredDescription
AuthorizationstringYesBearer {access_token}
Content-TypestringYesapplication/json

Response- Logout confirmation

json
{
  "message": "Successfully logged out"
}

Request Payload

json
{
  "refresh_token": "eyJhbGciOiJIUzI1NiIs..."
}

Example Request

bash
curl -X POST "https://api.example.com/auth/logout" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIs..." \
  -H "Content-Type: application/json" \
  -d '{
    "refresh_token": "eyJhbGciOiJIUzI1NiIs..."
  }'

Client-Side Cleanup

After calling logout, ensure you clean up client-side state.

ActionDescription
Clear localStorageRemove admin_token, admin_refresh_token, pending_token
Clear cookiesIf using httpOnly cookies, the server handles this
Reset app stateClear any cached user data or session info
RedirectNavigate to login page

Password Reset

Request Password Reset

POST/auth/admin/password/reset/request

Initiates a password reset flow by sending a reset link to the user's email. For security, always returns success even if email doesn't exist.

Headers

ParameterTypeRequiredDescription
Content-TypestringYesapplication/json

Response- Always returns success for security

json
{
  "message": "If an account exists with this email, a reset link has been sent"
}

Request Payload

json
{
  "email": "admin@example.com"
}

Example Request

bash
curl -X POST "https://api.example.com/auth/admin/password/reset/request" \
  -H "Content-Type: application/json" \
  -d '{
    "email": "admin@example.com"
  }'

Confirm Password Reset

POST/auth/admin/password/reset/confirm

Completes the password reset using the token from the email link. The token is single-use and expires after a set period (typically 1 hour).

Headers

ParameterTypeRequiredDescription
Content-TypestringYesapplication/json

Response- Password reset confirmation

json
{
  "message": "Password has been reset successfully"
}

Request Payload (Confirm)

json
{
  "token": "rst_550e8400-e29b-41d4-a716-446655440000",
  "new_password": "NewSecureP@ssw0rd!"
}

Example Request (Confirm)

bash
curl -X POST "https://api.example.com/auth/admin/password/reset/confirm" \
  -H "Content-Type: application/json" \
  -d '{
    "token": "rst_550e8400-e29b-41d4-a716-446655440000",
    "new_password": "NewSecureP@ssw0rd!"
  }'

Password Requirements

RequirementDescription
Minimum LengthAt least 8 characters
UppercaseAt least one uppercase letter (A-Z)
LowercaseAt least one lowercase letter (a-z)
NumberAt least one digit (0-9)
Special CharacterAt least one special character (!@#$%^&*)
No Common PatternsCannot be a commonly used password

Error Responses

StatusCodeDescription
400invalid_tokenReset token is invalid or malformed
400token_expiredReset token has expired (> 1 hour)
400token_usedReset token has already been used
400weak_passwordPassword doesn't meet complexity requirements
429rate_limitedToo many reset attempts

Change Password

Change Admin Password

POST/auth/admin/password/change

Allows an authenticated admin to change their password. Requires current password verification and optionally MFA code if enabled.

Headers

ParameterTypeRequiredDescription
AuthorizationstringYesBearer {access_token}
Content-TypestringYesapplication/json

Response- Password change confirmation

json
{
  "message": "Password changed successfully"
}

Request Payload

json
{
  "current_password": "OldP@ssw0rd!",
  "new_password": "NewSecureP@ssw0rd!",
  "mfa_code": "123456"
}

Request Payload (Without MFA)

json
{
  "current_password": "OldP@ssw0rd!",
  "new_password": "NewSecureP@ssw0rd!"
}

Example Request

bash
curl -X POST "https://api.example.com/auth/admin/password/change" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIs..." \
  -H "Content-Type: application/json" \
  -d '{
    "current_password": "OldP@ssw0rd!",
    "new_password": "NewSecureP@ssw0rd!",
    "mfa_code": "123456"
  }'

Error Responses

StatusCodeDescription
400invalid_current_passwordCurrent password is incorrect
400weak_passwordNew password doesn't meet requirements
400same_passwordNew password cannot be same as current
400mfa_requiredMFA code is required but not provided
400invalid_mfa_codeMFA code is invalid or expired
401unauthorizedAccess token is invalid or expired

Security Best Practices

Token Handling

PracticeDescription
Never log tokensAccess and refresh tokens should never be logged
Use HTTPS onlyAll auth requests must be over HTTPS
Rotate refresh tokensUse the new refresh token after each refresh
Set short expiryAccess tokens should expire in 15-30 minutes
Clear on logoutRemove all tokens from storage on logout

Error Handling

ScenarioRecommended Action
401 on any requestAttempt token refresh, retry once
Refresh failsClear tokens, redirect to login
403 ForbiddenShow access denied message
429 Rate LimitedShow retry message with countdown
Network errorShow offline message, queue for retry

Session Management

FeatureImplementation
Activity timeoutLogout after 30 minutes of inactivity
Multi-tab syncUse BroadcastChannel API to sync logout
Session listAllow users to view and revoke active sessions
Force logoutAdmin can force logout specific users