Page cover

Authentication

Authentication in the Proof of Me Unified API ensures that only authorized users and applications can interact with the API endpoints. This layer of security protects sensitive data and prevents unauthorized usage of the service.

The PoM API uses Bearer Token Authentication, where users need to provide a valid token in the headers of their API requests. This token is generated upon successful user registration and serves as the key to access the API's features.


How Authentication Works

  1. Token Generation:

    • A Bearer Token is issued during the registration process (POST /api/v1/user/register-user).

    • This token uniquely identifies the user and grants them access to the API endpoints.

  2. Using the Token:

    • The token must be included in the Authorization header for every API request.

    • If the token is missing, invalid, or expired, the request will be denied with an appropriate error response.

  3. Secure Your Token:

    • Never expose your Bearer Token in public repositories or client-side code.

    • Treat your token as sensitive information.


Example Header

To authenticate your requests, include the token in the Authorization header as shown below:

plaintextCopy codeAuthorization: Bearer your-generated-bearer-token

Example: Token in Use

Here’s an example of an API request with the Bearer Token included:

JavaScript Example

Python Example


Error Handling

If the Bearer Token is invalid or missing, the API will return an error response. Below are some common errors:

  • 401 Unauthorized: Missing or invalid Bearer Token.

  • 403 Forbidden: Token does not have access to the requested resource.

  • 498 Invalid Token: Token is expired or no longer valid.

Example Error Response:


Best Practices for Authentication

  • Keep Your Token Secure: Store your token in a secure location (e.g., environment variables).

  • Regenerate Tokens Regularly: If you suspect your token has been compromised, generate a new one through the registration endpoint.

  • Use HTTPS: Always make API calls over HTTPS to encrypt the communication.

Last updated