User registration and authentication
User Registration and Authentication Guide
This guide provides step-by-step instructions for user self-registration, authentication, and token refresh in our system. It includes details on how to use the “Accept-Language” header for localized responses and the “X-Device-ID” header for device identification.
Step 1: Initiate Registration
- Send a POST request to
/v1/users/initiate-registration
- Headers:
- Request Body:
- Expected Response (200 OK):
Step 2: Validate Credential
- Send a POST request to
/v1/users/verify-registration
- Headers:
- Request Body:
- Expected Response (200 OK):
Step 3: Authenticate User
- Send a POST request to
/v1/authenticate
- Headers:
- Request Body:
- Expected Response (200 OK):
Step 4: Verify 2FA (When Required)
2FA is automatically activated after verifying a second credential:
- Add a phone credential:
- Verify the phone credential:
Once a second credential is verified, 2FA will be automatically activated. For subsequent logins, after password authentication, you’ll need to complete 2FA verification. See Authentication API for details.
Step 5: Refresh Token
- Send a POST request to
/v1/refresh-token
- Headers:
- No request body is needed. The refresh token is automatically included via the HTTP-only cookie set during authentication.
- Expected Response (200 OK):
Note: A new refresh token will be set as an HTTP-only cookie in the response.
Step 6: Logout
- Send a POST request to
/v1/logout
- Headers:
- No request body is needed.
- Expected Response (200 OK):
Note: The refresh token cookie will be cleared during logout.
Important Notes
-
Language Localization:
- Use the
Accept-Language
header to specify your preferred language for response messages. - Supported values are
en
(English),de
(German),fr
(French), andit
(Italian). - If not specified, the system will default to English.
- Use the
-
Security:
- Always use HTTPS for all API communications.
- Store the access token securely on the client-side.
- The refresh token is automatically managed by the server using HTTP-only cookies.
-
Device Identification:
- Use a consistent
X-Device-ID
for the same device across all requests. - This is crucial for security, especially during authentication and token refresh operations.
- Use a consistent
-
Token Management:
- The access token has a shorter lifespan (15 minutes by default) than the refresh token (14 days by default).
- Implement logic to handle token expiration and refresh scenarios in your application.
- If authentication fails (401 Unauthorized), attempt to refresh the token. If that fails, prompt the user to re-enter their credentials.
-
Error Handling:
- Implement proper error handling for various HTTP status codes.
- Pay attention to rate limiting and temporary lock-out scenarios, especially during authentication.
-
Compliance:
- Ensure users accept the terms and conditions and privacy policy during registration.
- Handle user data in compliance with relevant data protection regulations.
-
CORS (Cross-Origin Resource Sharing):
- The API supports CORS for web applications.
- Allowed headers include:
Content-Type
,Authorization
,X-API-Key
,X-Device-ID
,Accept-Language
. - Specific origins may be restricted based on server configuration.
By following these steps and best practices, you can implement a secure and localized user registration and authentication process in your application.