Authentication API

The OSUS.AI Authentication API provides secure user authentication, registration, and session management with support for OAuth providers and multi-factor authentication.

Base URL: https://api.osus.ai/v1/auth

Features

JWT-based authentication
OAuth 2.0 integration
Multi-factor authentication
Session management

Authentication

All API requests require authentication via JWT tokens in the Authorization header.

Authorization: Bearer YOUR_JWT_TOKEN
Security Note

Always use HTTPS in production. Never expose your API tokens in client-side code.

User Registration

Register a new user account.

POST /auth/register

Request Body

Parameter Type Required Description
email string Yes User's email address
password string Yes Password (min 8 characters)
firstName string Yes User's first name
lastName string Yes User's last name
phone string No Phone number (Egyptian format)
accountType string No Account type: individual, business
referralCode string No Referral code from existing user

Example Request

curl -X POST https://api.osus.ai/v1/auth/register \
  -H "Content-Type: application/json" \
  -d '{
    "email": "ahmed@example.com",
    "password": "SecurePass123!",
    "firstName": "Ahmed",
    "lastName": "Mohamed",
    "phone": "+201234567890",
    "accountType": "individual"
  }'

Response

{
  "success": true,
  "data": {
    "user": {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "email": "ahmed@example.com",
      "firstName": "Ahmed",
      "lastName": "Mohamed",
      "accountType": "individual",
      "emailVerified": false,
      "createdAt": "2025-01-15T10:30:00Z"
    },
    "tokens": {
      "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
      "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
      "expiresIn": 3600
    }
  },
  "timestamp": "2025-01-15T10:30:00Z",
  "requestId": "req_123456"
}

User Login

Authenticate a user and receive access tokens.

POST /auth/login

Request Body

Parameter Type Required Description
email string Yes User's email address
password string Yes User's password
rememberMe boolean No Extended session duration
deviceInfo object No Device information for security

Example Request

curl -X POST https://api.osus.ai/v1/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "email": "ahmed@example.com",
    "password": "SecurePass123!",
    "rememberMe": true,
    "deviceInfo": {
      "type": "mobile",
      "platform": "iOS",
      "version": "17.2"
    }
  }'

Response

{
  "success": true,
  "data": {
    "user": {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "email": "ahmed@example.com",
      "firstName": "Ahmed",
      "lastName": "Mohamed",
      "loyaltyTier": "gold",
      "lastLogin": "2025-01-15T10:30:00Z"
    },
    "tokens": {
      "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
      "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
      "expiresIn": 3600
    },
    "mfaRequired": false
  },
  "timestamp": "2025-01-15T10:30:00Z",
  "requestId": "req_123457"
}

Token Refresh

Refresh an expired access token using a refresh token.

POST /auth/refresh

Request Body

Parameter Type Required Description
refreshToken string Yes Valid refresh token

Example Request

curl -X POST https://api.osus.ai/v1/auth/refresh \
  -H "Content-Type: application/json" \
  -d '{
    "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
  }'

OAuth Integration

Authenticate using third-party OAuth providers.

Supported Providers

Google
Facebook
Apple
POST /auth/oauth/{provider}

Example Request

curl -X POST https://api.osus.ai/v1/auth/oauth/google \
  -H "Content-Type: application/json" \
  -d '{
    "accessToken": "google_access_token_here",
    "idToken": "google_id_token_here"
  }'

Error Codes

HTTP Status Error Code Description
400 INVALID_CREDENTIALS Invalid email or password
400 EMAIL_ALREADY_EXISTS Email already registered
400 WEAK_PASSWORD Password doesn't meet requirements
401 INVALID_TOKEN JWT token is invalid or expired
401 MFA_REQUIRED Multi-factor authentication required
429 RATE_LIMIT_EXCEEDED Too many authentication attempts

Security Best Practices

Token Security
  • Store tokens securely (keychain/secure storage)
  • Use HTTPS for all requests
  • Implement token refresh logic
  • Clear tokens on logout
Password Requirements
  • Minimum 8 characters
  • At least one uppercase letter
  • At least one lowercase letter
  • At least one number or symbol