B2C Customer Authentication Flow
This guide details the complete authentication flow for individual (B2C) customers in the FinHub platform v2.1. The new APIs provide enhanced security through proper session management, role-based access control, and streamlined two-factor authentication. The process supports both admin operations (for customer management) and customer operations (for transactions).Key Improvements in v2.1
- Dual Token System: Separate tokens for admin and customer operations
- Session Management: X-Session-Id header for transaction security
- Role-Based Access: Clear separation between admin and customer permissions
- Enhanced 2FA: Support for multiple 2FA methods including TOTP
- Security Headers: X-Tenant-ID for multi-tenant isolation
Flow Overview
The following sequence diagram illustrates the enhanced B2C authentication process with v2.1 APIs:Authentication Types
The v2.1 API supports two distinct authentication flows:1. Admin Authentication
Used for customer management operations (registration, activation, verification)2. Customer Authentication
Used for customer-initiated operations (transfers, beneficiary management, account access)Detailed API Flow
Step 1: Admin Authentication (For Customer Management)
Admin authentication is required for managing customers. API Request:Step 2: Customer Authentication
Customers authenticate to access their accounts and perform transactions. API Request:- Session Management: Session ID required for all transaction operations
- Device Tracking: Device information for security monitoring
- Refresh Token: Allows token renewal without re-authentication
- IP Validation: Session bound to IP for security
Step 3: Get Customer Profile with Wallet Details
After authentication, retrieve the customer’s profile including wallet information. API Request:- Wallet Integration: Profile includes wallet and IBAN details
- Risk Profile: Shows customer category and risk level
- Security Settings: 2FA configuration and preferences
- Session Context: Current session information
Step 4: Two-Factor Authentication (For Sensitive Operations)
The v2.1 API requires 2FA for sensitive operations like high-value transfers or security changes. Triggering 2FA:- Session Elevation: 2FA elevates session for 30 minutes
- Device Trust: Option to trust device for future operations
- Multiple Methods: Support for SMS, Email, and TOTP
- Context-Aware: 2FA only required for sensitive operations
Step 5: Token Refresh
Use the refresh token to obtain new access tokens without re-authentication. API Request:Logout Process
Properly terminate the session and invalidate tokens. API Request:- Server invalidates session and tokens
- Clear all stored tokens and session data
- Reset application state
- Redirect to login page
Security Headers
All authenticated requests must include:Error Handling
Error Code | HTTP Status | Description |
---|---|---|
INVALID_CREDENTIALS | 401 | Username or password incorrect |
ACCOUNT_LOCKED | 423 | Account locked after failed attempts |
ACCOUNT_SUSPENDED | 403 | Account suspended by admin |
SESSION_EXPIRED | 401 | Session has expired |
INVALID_SESSION | 401 | Session ID invalid or not found |
TOKEN_EXPIRED | 401 | Access token has expired |
REFRESH_TOKEN_EXPIRED | 401 | Refresh token has expired |
INVALID_2FA_CODE | 422 | 2FA code incorrect |
2FA_CODE_EXPIRED | 422 | 2FA code has expired |
TOO_MANY_ATTEMPTS | 429 | Rate limit exceeded |
DEVICE_NOT_TRUSTED | 403 | Device requires verification |
IP_MISMATCH | 403 | Request from different IP |
Error Response Example:
Security Best Practices
-
Token Storage:
- Store access tokens in memory only
- Store refresh tokens in secure storage (httpOnly cookies)
- Never store tokens in localStorage for production
-
Session Management:
- Implement idle timeout (30 minutes)
- Maximum session duration (8 hours)
- Concurrent session limits
-
Device Security:
- Device fingerprinting
- Trusted device management
- New device notifications
-
Rate Limiting:
- 5 login attempts per 15 minutes
- 3 2FA attempts per code
- Progressive delays after failures
-
Monitoring:
- Log all authentication events
- Alert on suspicious patterns
- Geographic anomaly detection
Authentication Flows by Operation Type
Admin Operations
- Customer Registration: Admin token only
- Customer Activation: Admin token only
- Verification Approval: Admin token only
Customer Operations
- View Profile: Customer token + Session ID
- Manage Beneficiaries: Customer token + Session ID
- Execute Transfers: Customer token + Session ID + 2FA (if required)
Next Steps
After successful authentication:- View Account Dashboard
- Manage Beneficiaries
- Execute Transfers
- Configure Security Settings
- Set Up Webhooks