Authentication Service
The Authentication Service provides secure user authentication and authorization capabilities across your organization’s ecosystem. It manages user identity verification, session handling, and supports multiple authentication methods including password, one-time passwords (OTP), OAuth providers (Google, Microsoft), Azure AD, OAuth, and SAML SSO.Base URL
All endpoints are prefixed with/api/v1
Authentication
Most endpoints require authentication via Bearer token:PASSWORD_RESET- For password reset operationsTOKEN_REFRESH- For token refresh operationsFETCH_CONFIG- For configuration updates
Architecture Overview
The Authentication Service is built on a Node.js backend with MongoDB for data persistence and Redis for session management. The service implements a container-based dependency injection pattern using InversifyJS for better modularity and testability. Key components that the Auth Service integrates with:- IAM Service - Manages user and organization information
- Configuration Manager - Stores authentication provider configurations
- Communication Service - Handles email delivery for password resets and OTP
- Redis - Manages authentication sessions and temporary tokens
Authentication Flow Process
The Auth Service employs a multi-step session-based authentication flow:-
Authentication Initialization
- Client calls the
/userAccount/initAuthendpoint with an email - Server validates the email and creates a temporary session in Redis
- Server returns a session token in the
x-session-tokenresponse header along with available authentication methods
- Client calls the
-
Authentication Steps
- Client calls
/userAccount/authenticatewith the session token in thex-session-tokenheader - Client provides chosen authentication method and credentials
- If multi-factor authentication is configured, the server returns information about the next step
- Client repeats the authentication step with appropriate credentials until all required steps are completed
- Client calls
-
Token Issuance
- After successful authentication, the server issues access and refresh tokens
- The Redis session is cleared
- Client stores tokens for subsequent API calls
Data Models
OrgAuthConfig Schema
OrgAuthConfig Schema
UserCredentials Schema
UserCredentials Schema
UserActivities Schema
UserActivities Schema
Session Data
Session Data
Session Management with Redis
The Auth Service uses Redis to store temporary session data during the authentication process:- Sessions are identified by a unique UUID token
- The x-session-token header is used to track the session across requests
- Sessions expire after a configurable period (default: 1 hour)
- Session data includes authentication state, user info, and available auth methods
- After successful authentication, sessions are deleted from Redis
Token-Based Authentication
After successful authentication, the service issues two types of JWTs:-
Access Token
- Short-lived token (typically 1 hour)
- Contains user ID, organization ID, user email, and permissions
- Used for authorizing API requests across services
-
Refresh Token
- Longer-lived token (typically 7 days)
- Used to obtain new access tokens when they expire
- Prevents the need for frequent re-authentication
API Endpoints
Authentication Flow
Authentication Flow
POST /userAccount/initAuth - Initialize Authentication
POST /userAccount/initAuth - Initialize Authentication
- Request
- Response
POST /api/v1/userAccount/initAuthRequest Body Parameters:| Parameter | Type | Required | Description |
|---|---|---|---|
| string | Yes | The user’s email address |
POST /userAccount/authenticate - Authenticate User
POST /userAccount/authenticate - Authenticate User
- Request
- Response
POST /api/v1/userAccount/authenticateHeaders:| Header | Value | Required | Description |
|---|---|---|---|
| x-session-token | string | Yes | Session token obtained from the initAuth response headers |
| Parameter | Type | Required | Description |
|---|---|---|---|
| method | string | Yes | Authentication method (password, otp, google, microsoft, azureAd, oauth, samlSso) |
| credentials | object | Yes | Credentials object for the specified method |
OTP Authentication
OTP Authentication
POST /userAccount/login/otp/generate - Generate OTP
POST /userAccount/login/otp/generate - Generate OTP
- Request
- Response
POST /api/v1/userAccount/login/otp/generateRequest Body Parameters:| Parameter | Type | Required | Description |
|---|---|---|---|
| string | Yes | The user’s email address (must be valid email format) |
- Email must be in valid email format
- Request goes through ValidationMiddleware with email validation
OAuth Integration
OAuth Integration
POST /userAccount/oauth/exchange - Exchange OAuth Token
POST /userAccount/oauth/exchange - Exchange OAuth Token
- Request
- Response
POST /api/v1/userAccount/oauth/exchangeRequest Body Parameters:| Parameter | Type | Required | Description |
|---|---|---|---|
| code | string | Yes | Authorization code from OAuth provider |
| string | Yes | User’s email address | |
| provider | string | Yes | OAuth provider name |
| redirectUri | string | Yes | Redirect URI used in OAuth flow |
Password Management
Password Management
POST /userAccount/password/forgot - Forgot Password
POST /userAccount/password/forgot - Forgot Password
- Request
- Response
POST /api/v1/userAccount/password/forgotRequest Body Parameters:| Parameter | Type | Required | Description |
|---|---|---|---|
| string | Yes | The user’s email address |
POST /userAccount/password/reset/token - Reset Password with Token
POST /userAccount/password/reset/token - Reset Password with Token
- Request
- Response
POST /api/v1/userAccount/password/reset/tokenHeaders:| Header | Value | Required | Description |
|---|---|---|---|
| Authorization | Bearer | Yes | Password reset token from email (uses PASSWORD_RESET scope) |
| Parameter | Type | Required | Description |
|---|---|---|---|
| password | string | Yes | New password (must meet complexity requirements) |
POST /userAccount/password/reset - Change Password
POST /userAccount/password/reset - Change Password
- Request
- Response
POST /api/v1/userAccount/password/resetHeaders:| Header | Value | Required | Description |
|---|---|---|---|
| Authorization | Bearer | Yes | Valid access token (requires user authentication) |
| Parameter | Type | Required | Description |
|---|---|---|---|
| currentPassword | string | Yes | Current password |
| newPassword | string | Yes | New password (must meet complexity requirements) |
Token Management
Token Management
POST /userAccount/refresh/token - Refresh Token
POST /userAccount/refresh/token - Refresh Token
- Request
- Response
POST /api/v1/userAccount/refresh/tokenHeaders:| Header | Value | Required | Description |
|---|---|---|---|
| Authorization | Bearer | Yes | Valid refresh token (uses TOKEN_REFRESH scope) |
POST /userAccount/logout/manual - Logout
POST /userAccount/logout/manual - Logout
- Request
- Response
POST /api/v1/userAccount/logout/manualHeaders:| Header | Value | Required | Description |
|---|---|---|---|
| Authorization | Bearer | Yes | Valid access token (requires user authentication) |
SAML SSO Integration
SAML SSO Integration
GET /saml/signIn - SAML Sign-In
GET /saml/signIn - SAML Sign-In
- Request
- Response
GET /api/v1/saml/signInQuery Parameters:| Parameter | Type | Required | Description |
|---|---|---|---|
| string | Yes | The user’s email address | |
| sessionToken | string | Yes | Session token from init authentication |
POST /saml/signIn/callback - SAML Callback
POST /saml/signIn/callback - SAML Callback
- Request
- Response
POST /api/v1/saml/signIn/callbackThis endpoint is called by the Identity Provider after successful authentication.
No manual parameters needed as this is part of the SAML flow.POST /saml/updateAppConfig - Update SAML App Config
POST /saml/updateAppConfig - Update SAML App Config
- Request
- Response
POST /api/v1/saml/updateAppConfigHeaders:| Header | Value | Required | Description |
|---|---|---|---|
| Authorization | Bearer | Yes | Valid scoped token with FETCH_CONFIG scope |
Organization Auth Configuration
Organization Auth Configuration
GET /orgAuthConfig/authMethods - Get Auth Methods
GET /orgAuthConfig/authMethods - Get Auth Methods
- Request
- Response
GET /api/v1/orgAuthConfig/authMethodsHeaders:| Header | Value | Required | Description |
|---|---|---|---|
| Authorization | Bearer | Yes | Valid admin access token |
POST /orgAuthConfig/updateAuthMethod - Update Auth Methods
POST /orgAuthConfig/updateAuthMethod - Update Auth Methods
- Request
- Response
POST /api/v1/orgAuthConfig/updateAuthMethodHeaders:| Header | Value | Required | Description |
|---|---|---|---|
| Authorization | Bearer | Yes | Valid admin access token |
| Parameter | Type | Required | Description |
|---|---|---|---|
| authMethod | array | Yes | Array of authentication steps |
- Must have between 1 and 3 authentication steps
- Each step must have a unique order number
- At least one authentication method is required per step
- No duplicate authentication methods within the same step
- No duplicate authentication methods across different steps
- Each authentication method can only be used once in the entire configuration
password- Username/password authenticationotp- One-time password via emailgoogle- Google OAuth authenticationmicrosoft- Microsoft OAuth authenticationazureAd- Azure Active Directory authenticationoauth- Generic OAuth authenticationsamlSso- SAML Single Sign-On
POST /orgAuthConfig/ - Setup Org Auth Config
POST /orgAuthConfig/ - Setup Org Auth Config
- Request
- Response
POST /api/v1/orgAuthConfig/Headers:| Header | Value | Required | Description |
|---|---|---|---|
| Authorization | Bearer | Yes | Valid admin access token |
| Parameter | Type | Required | Description |
|---|---|---|---|
| contactEmail | string | Yes | Organization contact email |
| registeredName | string | Yes | Organization registered name |
| adminFullName | string | Yes | Admin’s full name |
| sendEmail | boolean | No | Whether to send email notifications (default: false) |
Internal Endpoints
Internal Endpoints
GET /userAccount/internal/password/check - Check Password Method
GET /userAccount/internal/password/check - Check Password Method
- Request
- Response
GET /api/v1/userAccount/internal/password/checkHeaders:| Header | Value | Required | Description |
|---|---|---|---|
| Authorization | Bearer | Yes | Valid scoped token with FETCH_CONFIG scope |
Security Considerations
The Authentication Service implements several security measures:Password Security
- Passwords are validated for complexity requirements (minimum 8 characters with at least one uppercase, one lowercase, one number, and one special character)
- Passwords are hashed using bcrypt with salt rounds
- Password reset links have limited validity
Brute Force Protection
- Failed login attempts are tracked per user account
- Accounts are automatically blocked after 5 consecutive failed attempts
- Suspicious login attempts trigger notification emails
- Blocked accounts require admin intervention to restore access
Session Security
- Session tokens are generated as UUIDs
- Sessions have limited lifetime (default: 1 hour) and are stored in Redis
- Sessions are invalidated after successful authentication or timeout
- Session data is encrypted and contains minimal user information
JWT Security
- Tokens are signed with secure secrets
- Different scopes are used for different token types (auth, refresh, password reset, etc.)
- Access tokens have short lifetimes (typically 1 hour)
- Refresh tokens have longer lifetimes (typically 7 days)
OAuth Security
- OAuth tokens are validated against provider endpoints
- Email verification ensures token authenticity
- Provider-specific validation for Google, Microsoft, and Azure AD
- Generic OAuth support with configurable endpoints
SAML Security
- SAML responses are cryptographically verified
- Certificate-based validation
- Configurable email field mapping
- Relay state protection against CSRF attacks
Error Handling
All endpoints return structured error responses:AUTHENTICATION_FAILED- Invalid credentialsSESSION_EXPIRED- Session token expiredINVALID_TOKEN- Invalid or malformed tokenUSER_BLOCKED- Account is blocked due to failed attemptsVALIDATION_ERROR- Invalid request parametersUNAUTHORIZED- Missing or invalid authenticationFORBIDDEN- Insufficient permissionsNOT_FOUND- Resource not foundINTERNAL_ERROR- Server error
Important Notes
- Session Token Management: The
x-session-tokenheader is critical for multi-step authentication flows - Password Complexity: Passwords must meet minimum security requirements
- Account Blocking: Users are automatically blocked after 5 failed login attempts
- Token Scopes: Different endpoints require different token scopes for access
- Multi-Factor Authentication: Organizations can configure multiple authentication steps
- Provider Configuration: OAuth and SAML providers require proper configuration
- Email Validation: All email fields are validated for proper format
- Security Headers: Proper headers must be included for authentication flows













