moovexDocs

Authentication

Authentication methods and token management for Fleet Orchestrator API

Authentication

Fleet Orchestrator uses token-based authentication. This guide covers login flows, token management, and best practices.

Authentication Flow

1. Login with credentials → Get access token + refresh token
2. Use access token for API requests
3. When access token expires → Use refresh token to get new access token
4. When refresh token expires → Login again

Login

Obtain tokens by authenticating with your credentials:

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

Response

{
  "accessToken": "eyJhbGciOiJIUzI1NiIs...",
  "refreshToken": "eyJhbGciOiJIUzI1NiIs...",
  "expiresIn": 3600,
  "user": {
    "_id": "user_123",
    "email": "your-email@example.com",
    "role": "admin",
    "companyRef": "company_456",
    "siteRef": "site_789"
  }
}
FieldDescription
accessTokenJWT token for API requests (short-lived)
refreshTokenToken to obtain new access tokens (long-lived)
expiresInAccess token lifetime in seconds
userAuthenticated user details

Using Access Tokens

Include the access token in the Authorization header:

curl https://api.moovex.ai/api/v1/reservations \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIs..."

Token Refresh

When the access token expires, use the refresh token to obtain a new one:

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

Response

{
  "accessToken": "eyJhbGciOiJIUzI1NiIs...",
  "expiresIn": 3600
}

Token Expiration

TokenLifetimeAction When Expired
Access Token1 hourRefresh using refresh token
Refresh Token7 daysLogin again

Auto-Login

For server-to-server integrations, you can use auto-login with a long-lived API key:

curl -X POST https://api.moovex.ai/api/v1/auth/auto-login \
  -H "Content-Type: application/json" \
  -d '{
    "apiKey": "your-api-key"
  }'

Contact support to obtain an API key for your account.

Who Am I

Verify your current authentication and get user details:

curl https://api.moovex.ai/api/v1/auth/whoami \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN"

Response

{
  "user": {
    "_id": "user_123",
    "email": "your-email@example.com",
    "firstName": "John",
    "lastName": "Doe",
    "role": "admin",
    "permissions": ["read", "write", "admin"]
  },
  "company": {
    "_id": "company_456",
    "name": "Acme Transportation"
  },
  "site": {
    "_id": "site_789",
    "name": "NYC Operations"
  }
}

User Roles

RoleDescription
adminFull access to all resources and settings
dispatcherManage reservations, trips, and drivers
viewerRead-only access
driverAccess to assigned trips only (driver app)

Error Responses

Invalid Credentials

{
  "statusCode": 401,
  "message": "Invalid email or password"
}

Token Expired

{
  "statusCode": 401,
  "message": "Token expired",
  "code": "TOKEN_EXPIRED"
}

Invalid Token

{
  "statusCode": 401,
  "message": "Invalid token",
  "code": "INVALID_TOKEN"
}

Best Practices

  1. Store tokens securely - Never expose tokens in client-side code or logs
  2. Implement token refresh - Proactively refresh tokens before expiration
  3. Handle 401 errors - Automatically refresh and retry when receiving 401
  4. Use API keys for servers - For backend integrations, use long-lived API keys
  5. Scope appropriately - Create users with minimum required permissions

Two-Factor Authentication

If 2FA is enabled for your account, the login flow requires an additional step:

Step 1: Initial Login

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

Response (2FA Required)

{
  "requires2FA": true,
  "tempToken": "temp_abc123"
}

Step 2: Verify OTP

curl -X POST https://api.moovex.ai/api/v1/auth/otp/check \
  -H "Content-Type: application/json" \
  -d '{
    "tempToken": "temp_abc123",
    "otp": "123456"
  }'

This returns the standard login response with access and refresh tokens.