Authentication For Apps
Authentication ensures that all requests made to the Tuku Pay Gateway are secure and identifiable to the specific app. Below are the details and processes for app authentication.
Authentication Overview
App-Specific Credentials:
Each app is issued:
A unique app ID (
appId
) for identification.An API key (
apiKey
) for secure authentication of requests.
The appId and apiKey must be included in the headers of every API request.
Token-Based Authentication (Optional Advanced Security):
Apps may also implement a token-based authentication system using a secret key for generating short-lived tokens.
This provides an extra layer of security, especially for apps with sensitive operations.
Security Measures:
All API requests must be made over HTTPS.
Requests from unregistered or non-whitelisted servers will be rejected.
Apps should securely store their
apiKey
and never expose it publicly.
Authentication Process
1. Obtaining App Credentials
When an app is registered, it is issued the following:
App ID (
appId
): A globally unique identifier for the app.API Key (
apiKey
): A secure key for authenticating all requests.
Example Response Upon Registration:
2. Authenticating API Requests
All API requests must include the following headers for authentication:
Request Headers:
Authorization: Contains the API key of the app.
X-App-ID: Contains the unique app ID.
Example Request:
Endpoints for Managing Authentication
1. Regenerate API Key
Used to regenerate an API key in case it is compromised.
Method:
POST
URL:
/api/apps/{appId}/regenerate-api-key
Request Headers:
Response:
2. Validate API Key
Checks the validity of an app’s API key.
Method:
GET
URL:
/api/auth/validate-key
Request Headers:
Response (Valid Key):
Response (Invalid Key):
Optional: Token-Based Authentication
For advanced security, apps can generate tokens using a secret key. These tokens are short-lived and tied to specific requests.
Token Generation (App Side)
Apps can generate tokens using a secret key provided during registration. The token payload may include:
appId
timestamp
request payload (hashed)
Example Token:
Best Practices for Authentication
Secure Storage:
Store the
apiKey
in a secure environment (e.g., environment variables).Avoid hardcoding credentials into source code or exposing them in client-side code.
Key Rotation:
Periodically regenerate the
apiKey
to reduce security risks.
Monitor Usage:
Monitor app activity and track API usage logs to detect unauthorized access or anomalies.
IP Whitelisting:
Whitelist only trusted IP addresses or server domains for your app.
Use HTTPS:
Always use HTTPS for secure communication with the Tuku Pay Gateway.
Notes
Authentication Failure: Any request without valid credentials will be rejected with a
401 Unauthorized
status.Custom Headers:
Apps may include additional headers for specific functionality or customizations.
Audit Logs:
All authentication requests and token generations are logged for auditing purposes.
Error Responses: Authentication errors will include a detailed error message. Example: