Skip to main content

Authentication

Overview​

To securely interact with Paytently's API, all requests must be authenticated using JSON Web Tokens (JWT) using the OAuth client credentials standard flow. This ensures that only authorized users and systems can access the API endpoints. This guide provides a step-by-step explanation of the JWT authentication flow.

At a basic level our authentication flow is as follows:

  1. Make a POST request our /auth/token endpoint with your credentials
  2. The API response will contain a bearer access_token
  3. Include this access_token in the header of all API requests: Authorization: Bearer {access_token}

Client credentials​

To begin the authentication process, you will have a Client ID and Client Secret provided to you by Paytently. Your client secrets should be encrypted and stored securely. Once generated, we can regenerate the secret for you, but we cannot retrieve it. Client credentials are linked to an entity and application. To provide flexibility, each application can have multiple sets of credentials if desired.

Request an access token​

When requesting a new JWT, you provide your client_id and client_secret.

The grant_type and audience fields are both required and are sent in the form body alongside your credentials. Set grant_type to client_credentials and audience to the URL of the environment you are using.

  • Sandbox audience: https://sandbox.api.paytently.io
  • Production audience: https://api.paytently.io
info

This request uses the x-www-form-urlencoded header content type. This is different to all our other APIs.

Request:

curl --location 'https://sandbox.api.paytently.io/auth/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'audience=https://sandbox.api.paytently.io' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'client_id=your-client-id' \
--data-urlencode 'client_secret=your-client-secret' \

Response:

{
"access_token": "your-jwt-access-token",
"expires_in": 3600,
"scope": "",
"token_type": "bearer"
}
Response parameterDescription
access_tokenThe JWT that will be used in future API requests.
expires_inThe token's expiration time in seconds.
scopeThe scopes granted to the token, separated by spaces.
token_typeAlways bearer. Send the token in the Authorization: Bearer header.

Including token in API requests​

After receiving the JWT, include it in the Authorization header of each subsequent API request.

You will be able to perform actions:

  • Only whilst the token is not expired
  • Only for the entity and application assigned to the token.

API Request with Token:

POST /payments
Authorization: Bearer your-jwt-access-token

Token expiration and renewal​

JWTs are time-limited and will expire after a certain period. If you receive a 401 Unauthorized response, your token may have expired. To renew your token you will need to request a new one with your client_id and client_secret.

warning

Your application should handle token expiration and request a new token before it expires. We recommend ensuring a token has at least 10 seconds of validity prior to performing any action

Unauthorized vs forbidden access​

All our endpoints can return 401 Unauthorized, 403 Forbidden or 404 Not Found

401 will be returned when:

  • The client credentials provided to authenticate to the /auth/token endpoint are incorrect
  • The token provided to the any other endpoint is unknown/expired

403 will be returned when:

  • The token used is not allowed to interact with the specific endpoint

404 will be returned when:

  • The token used is not allowed to interact with the specific resource to due ownership mismatch.