Auth Service API
The Auth Service handles user authentication, role-based access control (RBAC), and API key management. It provides secure JWT-based authentication and granular permission management for multi-tenant applications.Base URL:
https://paymentgateway.redahaloubi.com/api/v1All endpoints are prefixed with /api/v1Authentication Methods
The Auth Service supports multiple authentication methods depending on the use case:- JWT Tokens
Use Case: Dashboard, merchant portals, web applicationsToken Lifecycle:
- Access Token: 24 hours
- Refresh Token: 7 days
- Algorithm: HS256 (HMAC-SHA256)
/auth/login endpointRate Limits
Login Endpoint
5 requests per minute per IP addressAfter 5 failed login attempts, account is locked for 30 minutes
Register Endpoint
7 requests per hour per IP addressPrevents spam account creation
Other Endpoints
100 requests per second per userStandard rate limit for authenticated endpoints
API Key Endpoints
50 requests per second per merchantUsed for payment processing
Authentication Endpoints
Register User
/auth/registerFull name of the userMin length: 2 characters
Valid email addressFormat: Standard email validationUnique: Must not be already registered
Secure passwordMin length: 8 charactersSecurity: Hashed with bcrypt (cost 10)
Error Responses
Error Responses
400 Bad Request - Email Already Exists400 Bad Request - Weak Password400 Bad Request - Invalid Email429 Too Many Requests
Login
/auth/loginRegistered email address
User’s password
Error Responses
Error Responses
401 Unauthorized - Invalid Credentials401 Unauthorized - Account Locked401 Unauthorized - Account Suspended429 Too Many Requests
Refresh Token
/auth/refreshValid refresh token from login response
Error Responses
Error Responses
401 Unauthorized - Invalid Refresh Token401 Unauthorized - Token Revoked
Token Rotation: Each refresh returns a new access token and a new refresh token. The old refresh token is invalidated.
Get Profile
/auth/profileError Responses
Error Responses
401 Unauthorized - Missing Token401 Unauthorized - Invalid Token
Logout
/auth/logoutSingle Device Logout: This only logs out the current session. To logout from all devices, use the “Logout All” endpoint (coming soon).
Change Password
/auth/change-passwordCurrent password for verification
New password (min 8 characters)
Error Responses
Error Responses
400 Bad Request - Incorrect Old Password400 Bad Request - Weak Password400 Bad Request - Same Password
Get Sessions
/auth/sessionsSession Management: The
is_current flag indicates the session making this request. All sessions expire automatically after 24 hours.Role & Permission Endpoints
Get All Roles
/rolesRole Hierarchy
1
Owner
Full Control
- All permissions
- Cannot be removed
- Automatically assigned on merchant creation
- Can manage team and assign roles
2
Admin
Administrative Access
- Manage payments, invoices, reports
- Manage team members (except owner)
- Configure settings and webhooks
- Cannot delete merchant
3
Manager
Operational Access
- Create and manage payments
- Issue refunds
- View reports
- Cannot manage team or settings
4
Staff
Limited Access
- View transactions
- Create payments
- No refund capability
- Read-only access to reports
Get Role Details
/roles/:idRole ID (e.g.,
role_admin_456)Permission Format
All permissions follow theresource:action format:
Resources
transactionsinvoicesteamsettingsreportsapi_keys
Actions
read- View datacreate- Create new recordsupdate- Modify existing recordsdelete- Remove recordsmanage- Full CRUD access
Assign Role to User
/roles/assignteam:manage in the target merchant
Request Body
ID of the user receiving the role
ID of the role to assign
ID of the merchant context
Error Responses
Error Responses
403 Forbidden - Insufficient Permissions404 Not Found - User Not Found409 Conflict - Role Already Assigned
Remove Role from User
/roles/assignteam:manage in the target merchant
Request Body
ID of the user
ID of the role to remove
ID of the merchant context
Get User Roles
/roles/user/:user_id/merchant/:merchant_idUser ID
Merchant ID
Get User Permissions
/roles/user/:user_id/merchant/:merchant_id/permissionsUser ID
Merchant ID
Permission Caching: Permissions are cached in Redis for 10 minutes for fast validation. Changes to roles take effect within 10 minutes.
Security Best Practices
Password Security
Password Security
Requirements:
- Minimum 8 characters
- Use a mix of uppercase, lowercase, numbers, and symbols
- Avoid common passwords and dictionary words
- Passwords are hashed with bcrypt (cost factor 10)
- Original passwords are never stored or logged
- Cannot be retrieved, only reset
Token Management
Token Management
Access Tokens:
- 24-hour expiry
- Stored hashed in database (SHA-256)
- Automatically revoked on password change
- 7-day expiry
- Single-use (rotated on each refresh)
- Revoked on logout
- Store tokens securely (e.g., httpOnly cookies, secure storage)
- Never expose tokens in URLs or logs
- Implement token refresh before expiry
API Key Security
API Key Security
Generation:
- Cryptographically secure random generation
- 64 characters of entropy
- SHA-256 hashed in database
- Use different keys for production and testing
- Rotate keys every 90 days
- Never commit keys to version control
- Use environment variables or secrets managers
- Track last_used_at for each key
- Alert on unusual usage patterns
- Deactivate unused keys
Session Management
Session Management
Session Tracking:
- IP address and user agent logged
- Session duration: 24 hours
- Concurrent sessions allowed
- Logout: Current session only
- Password change: All sessions
- Manual revocation: Specific session
- Sessions cached for fast validation
- TTL matches token expiry
- Automatic cleanup on expiry
Account Protection
Account Protection
Failed Login Protection:
- 5 attempts = 30-minute lockout
- Tracked per email address
- Automatic unlock after timeout
- Login: 5 requests/minute per IP
- Register: 3 requests/hour per IP
- API calls: 100 requests/second per user
- Login from new IP/device logs event
- Multiple failed attempts trigger alert
- Account suspension for security violations
Error Reference
Common error codes and their meanings:Invalid request format, missing required fields, or validation errorsCommon causes:
- Missing required fields
- Invalid email format
- Password too short
- Invalid UUID format
Authentication failed or token invalidCommon causes:
- Missing Authorization header
- Expired access token
- Invalid API key
- Account locked or suspended
Authenticated but lacks required permissionsCommon causes:
- Insufficient role permissions
- Attempting to access another merchant’s data
- Trying to perform owner-only actions
Requested resource doesn’t existCommon causes:
- Invalid user ID
- Role ID not found
- API key doesn’t exist
Request conflicts with current stateCommon causes:
- Email already registered
- Role already assigned
- API key name already exists
Rate limit exceededResponse includes:
retry_after: Seconds until next allowed request- Rate limit headers showing remaining quota
Unexpected server errorAction:
- Retry the request
- Contact support if persistent
Rate Limit Headers
All responses include rate limit information:Maximum requests allowed in the current window
Requests remaining in the current window
Unix timestamp when the rate limit resets
Endpoint category (e.g., auth, payments, etc.)
Next Steps
Merchant API
Manage merchants, teams, and settings
Payment API
Process payments and manage transactions
Quick Start
Create your first payment intent
CLI Tool
Command-line interface for testing
Questions? Contact support at [email protected]