Skip to main content

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/v1

Authentication Methods

The Auth Service supports multiple authentication methods depending on the use case:
Use Case: Dashboard, merchant portals, web applications
Token Lifecycle:
  • Access Token: 24 hours
  • Refresh Token: 7 days
  • Algorithm: HS256 (HMAC-SHA256)
Obtain tokens via: /auth/login endpoint

Rate 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

endpoint
/auth/register
Create a new user account. Email verification is required before full access. Request Body
string
required
Full name of the userMin length: 2 characters
string
required
Valid email addressFormat: Standard email validationUnique: Must not be already registered
string
required
Secure passwordMin length: 8 charactersSecurity: Hashed with bcrypt (cost 10)
Example Request
Response (201 Created)
400 Bad Request - Email Already Exists
400 Bad Request - Weak Password
400 Bad Request - Invalid Email
429 Too Many Requests

Login

endpoint
/auth/login
Authenticate user and receive JWT access and refresh tokens. Request Body
string
required
Registered email address
string
required
User’s password
Example Request
Response (200 OK)
401 Unauthorized - Invalid Credentials
401 Unauthorized - Account Locked
401 Unauthorized - Account Suspended
429 Too Many Requests
Account Lockout Policy:
  • After 5 failed login attempts, the account is locked for 30 minutes
  • Failed attempts are tracked per email address
  • Lockout is automatic and cannot be manually bypassed

Refresh Token

endpoint
/auth/refresh
Get a new access token using a refresh token. Use this to maintain user sessions without requiring re-login. Request Body
string
required
Valid refresh token from login response
Example Request
Response (200 OK)
401 Unauthorized - Invalid Refresh Token
401 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

endpoint
/auth/profile
Get the authenticated user’s profile information. Authentication Required: JWT Bearer Token Example Request
Response (200 OK)
401 Unauthorized - Missing Token
401 Unauthorized - Invalid Token

Logout

endpoint
/auth/logout
Revoke the current session and invalidate the access token. Authentication Required: JWT Bearer Token Example Request
Response (200 OK)
Single Device Logout: This only logs out the current session. To logout from all devices, use the “Logout All” endpoint (coming soon).

Change Password

endpoint
/auth/change-password
Change the user’s password. This action logs out all sessions and requires re-login. Authentication Required: JWT Bearer Token Request Body
string
required
Current password for verification
string
required
New password (min 8 characters)
Example Request
Response (200 OK)
400 Bad Request - Incorrect Old Password
400 Bad Request - Weak Password
400 Bad Request - Same Password
Security Notice: Changing password will revoke all active sessions on all devices. User must login again with the new password.

Get Sessions

endpoint
/auth/sessions
List all active sessions for the authenticated user across all devices. Authentication Required: JWT Bearer Token Example Request
Response (200 OK)
Session Management: The is_current flag indicates the session making this request. All sessions expire automatically after 24 hours.

Role & Permission Endpoints

Get All Roles

endpoint
/roles
Get a list of all available roles in the system. Authentication Required: JWT Bearer Token Example Request
Response (200 OK)

Role 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

endpoint
/roles/:id
Get detailed information about a specific role including all its permissions. Authentication Required: JWT Bearer Token Path Parameters
string
required
Role ID (e.g., role_admin_456)
Example Request
Response (200 OK)

Permission Format

All permissions follow the resource:action format:

Resources

  • transactions
  • invoices
  • team
  • settings
  • reports
  • api_keys

Actions

  • read - View data
  • create - Create new records
  • update - Modify existing records
  • delete - Remove records
  • manage - Full CRUD access

Assign Role to User

endpoint
/roles/assign
Assign a role to a user for a specific merchant. Users can have different roles across different merchants. Authentication Required: JWT Bearer Token Required Permission: team:manage in the target merchant Request Body
string
required
ID of the user receiving the role
string
required
ID of the role to assign
string
required
ID of the merchant context
Example Request
Response (200 OK)
403 Forbidden - Insufficient Permissions
404 Not Found - User Not Found
409 Conflict - Role Already Assigned

Remove Role from User

endpoint
/roles/assign
Remove a role assignment from a user in a specific merchant. Authentication Required: JWT Bearer Token Required Permission: team:manage in the target merchant Request Body
string
required
ID of the user
string
required
ID of the role to remove
string
required
ID of the merchant context
Example Request
Response (200 OK)
Cannot Remove Owner: The Owner role cannot be removed. Transfer ownership to another user before attempting removal.

Get User Roles

endpoint
/roles/user/:user_id/merchant/:merchant_id
Get all roles assigned to a user in a specific merchant. Authentication Required: JWT Bearer Token Path Parameters
string
required
User ID
string
required
Merchant ID
Example Request
Response (200 OK)

Get User Permissions

endpoint
/roles/user/:user_id/merchant/:merchant_id/permissions
Get all effective permissions for a user in a specific merchant (aggregated from all assigned roles). Authentication Required: JWT Bearer Token Path Parameters
string
required
User ID
string
required
Merchant ID
Example Request
Response (200 OK)
Permission Caching: Permissions are cached in Redis for 10 minutes for fast validation. Changes to roles take effect within 10 minutes.

Security Best Practices

Requirements:
  • Minimum 8 characters
  • Use a mix of uppercase, lowercase, numbers, and symbols
  • Avoid common passwords and dictionary words
Storage:
  • Passwords are hashed with bcrypt (cost factor 10)
  • Original passwords are never stored or logged
  • Cannot be retrieved, only reset
Access Tokens:
  • 24-hour expiry
  • Stored hashed in database (SHA-256)
  • Automatically revoked on password change
Refresh Tokens:
  • 7-day expiry
  • Single-use (rotated on each refresh)
  • Revoked on logout
Best Practices:
  • Store tokens securely (e.g., httpOnly cookies, secure storage)
  • Never expose tokens in URLs or logs
  • Implement token refresh before expiry
Generation:
  • Cryptographically secure random generation
  • 64 characters of entropy
  • SHA-256 hashed in database
Usage:
  • Use different keys for production and testing
  • Rotate keys every 90 days
  • Never commit keys to version control
  • Use environment variables or secrets managers
Monitoring:
  • Track last_used_at for each key
  • Alert on unusual usage patterns
  • Deactivate unused keys
Session Tracking:
  • IP address and user agent logged
  • Session duration: 24 hours
  • Concurrent sessions allowed
Session Invalidation:
  • Logout: Current session only
  • Password change: All sessions
  • Manual revocation: Specific session
Redis Storage:
  • Sessions cached for fast validation
  • TTL matches token expiry
  • Automatic cleanup on expiry
Failed Login Protection:
  • 5 attempts = 30-minute lockout
  • Tracked per email address
  • Automatic unlock after timeout
Rate Limiting:
  • Login: 5 requests/minute per IP
  • Register: 3 requests/hour per IP
  • API calls: 100 requests/second per user
Suspicious Activity:
  • 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:
Bad Request
Invalid request format, missing required fields, or validation errorsCommon causes:
  • Missing required fields
  • Invalid email format
  • Password too short
  • Invalid UUID format
Unauthorized
Authentication failed or token invalidCommon causes:
  • Missing Authorization header
  • Expired access token
  • Invalid API key
  • Account locked or suspended
Forbidden
Authenticated but lacks required permissionsCommon causes:
  • Insufficient role permissions
  • Attempting to access another merchant’s data
  • Trying to perform owner-only actions
Not Found
Requested resource doesn’t existCommon causes:
  • Invalid user ID
  • Role ID not found
  • API key doesn’t exist
Conflict
Request conflicts with current stateCommon causes:
  • Email already registered
  • Role already assigned
  • API key name already exists
Too Many Requests
Rate limit exceededResponse includes:
  • retry_after: Seconds until next allowed request
  • Rate limit headers showing remaining quota
Internal Server Error
Unexpected server errorAction:
  • Retry the request
  • Contact support if persistent

Rate Limit Headers

All responses include rate limit information:
integer
Maximum requests allowed in the current window
integer
Requests remaining in the current window
integer
Unix timestamp when the rate limit resets
string
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]