Overview
Access tokens issued by Pleo are short-lived.To continue calling Pleo APIs, your integration must use the refresh token to obtain a new access token when the current one expires. Refreshing tokens:
- Happens without user interaction
- Must be handled server-side
- Must be safe against race conditions and retries
Steps
1. Determine When to Refresh Tokens
Your integration should refresh the access token when:- The token is about to expire (preferred), or
- An API call fails due to token expiration
expires_in value returned during token exchange to track expiry.
2. Send a Refresh Token Request
To refresh tokens, make a request to Pleo’s token endpoint using the refresh token grant. The request must include:grant_type:refresh_tokenrefresh_token: the current refresh tokenclient_idclient_secret
3. Handle the Token Refresh Response
A successful refresh response returns:- A new access token
- A new refresh token
- A new
expires_invalue
- Replace the stored access token
- Replace the stored refresh token
- Update the expiry timestamp
4. Centralise Token Refresh Logic
Token refresh must be implemented in a single, centralised location within your integration. This ensures:- Consistent behaviour across all API calls
- Easier monitoring and debugging
- Correct handling of retries and failures
5. Prevent Race Conditions
Multiple concurrent processes may detect token expiry at the same time. Your integration must ensure:- Only one refresh request is made at a time
- Other requests wait for the refreshed token
- Distributed locks
- In-memory mutexes
- Database-level locks
6. Handle Refresh Failures
Token refresh may fail due to:- Expired refresh token
- Revoked access
- Invalid client credentials
- Do not retry indefinitely
- Do not continue making API calls
- Mark the token state as invalid
7. Log Refresh Activity
Your integration should log:- Refresh attempts (timestamped)
- Success or failure outcomes
- Failure reasons (where available)
Result
After completing these steps:- Your integration refreshes access tokens without user involvement
- API access continues seamlessly across token expirations
- Token refresh behaviour is predictable, safe, and observable
What Comes Next?
How to Handle Token Expiry or Revocation
Learn how to recover safely when refresh tokens expire or access is revoked.
Related Reading
- Token Lifecycle
- OAuth 2.0 Client Registration – Step-by-step details of required fields, credentials, and redirect URIs.
- OAuth 2.0 Client Configuration – How to configure your client with correct endpoints, PKCE, and authentication methods.
- PKCE and Secured Patterns – Security requirements for public clients.