> ## Documentation Index
> Fetch the complete documentation index at: https://developers.pleo.io/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Handle Token Expiry or Revocation

export const WhatComesNext = ({children, href}) => <div className="mt-4">
    <a href={href} className="btn-primary">
      {children} →
    </a>
  </div>;

export const RememberCallout = ({title, children}) => <div className="callout-box callout-remember">
    <div className="callout-row">
      <span className="callout-icon">
        <svg width="22" height="22" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" fill="currentColor"><path d="M229.66,98.34,172.39,155.8c11.46,22.93-1.72,45.86-10.11,57a8,8,0,0,1-12,.83L42.34,105.76A8,8,0,0,1,43,93.85c29.65-23.92,57.4-10,57.4-10l57.27-57.46a8,8,0,0,1,11.31,0L229.66,87A8,8,0,0,1,229.66,98.34Z" opacity="0.2" /><path d="M235.32,81.37,174.63,20.69a16,16,0,0,0-22.63,0L98.37,74.49c-10.66-3.34-35-7.37-60.4,13.14a16,16,0,0,0-1.29,23.78L85,159.71,42.34,202.34a8,8,0,0,0,11.32,11.32L96.29,171l48.29,48.29A16,16,0,0,0,155.9,224c.38,0,.75,0,1.13,0a15.93,15.93,0,0,0,11.64-6.33c19.64-26.1,17.75-47.32,13.19-60L235.33,104A16,16,0,0,0,235.32,81.37ZM224,92.69h0l-57.27,57.46a8,8,0,0,0-1.49,9.22c9.46,18.93-1.8,38.59-9.34,48.62L48,100.08c12.08-9.74,23.64-12.31,32.48-12.31A40.13,40.13,0,0,1,96.81,91a8,8,0,0,0,9.25-1.51L163.32,32,224,92.68Z" /></svg>
      </span>
      <div>
        {title && <div className="callout-title">
            {title}
          </div>}
        <div className="callout-body">
          {children}
        </div>
      </div>
    </div>
  </div>;

This how-to explains how your integration should respond when OAuth 2.0 tokens can no longer be refreshed, ensuring users can reauthenticate cleanly and integrations fail safely.

## Overview

OAuth 2.0 access relies on **refresh tokens** to maintain long-lived access to Pleo APIs.\
In some situations, refresh tokens become **invalid** and can no longer be used to obtain new access tokens.

Common causes include:

* Refresh token expiry
* User revoking access
* Client credential rotation
* Security or policy changes

When this occurs, the integration must **stop API calls** and **restart the authorisation flow**.

## Steps

### 1. Detect Token Expiry or Revocation

Your integration may detect token expiry or revocation in the following ways.

**During token refresh:**

* The refresh token request returns an error (for example, an expired or invalid token)
* Pleo rejects the refresh request

**During API calls:**

* API requests fail with an authentication or authorisation error
* The error indicates that the access token is no longer valid and cannot be refreshed

<RememberCallout title="Remember">
  Always treat refresh token failures as terminal. Retrying refresh requests will not resolve revoked or expired tokens.
</RememberCallout>

***

### 2. Take Immediate Action

When token expiry or revocation is detected, your integration must:

1. Stop making further API requests using the invalid token
2. Mark the connection as **unauthenticated**
3. Invalidate stored access and refresh tokens
4. Require the user to reauthenticate

At this point, the OAuth 2.0 session cannot be recovered without user involvement.

***

### 3. Restart the Authorisation Flow

To restore access, the user must complete the OAuth 2.0 flow again.

Your integration should:

* Redirect the user to Pleo’s authorisation endpoint
* Request the required scopes again
* Handle the redirect and exchange a new authorisation code
* Store the newly issued access and refresh tokens

For implementation details, see:

* [How to Direct Users to the Authorisation Endpoint](/docs/current/how-tos/oauth/how-to-direct-users-to-the-authorisation-endpoint)
* [How to Handle Redirects and Exchange Authorisation Code](/docs/current/how-tos/oauth/how-to-handle-redirects-and-exchange-authorisation-code)

***

### 4. Design the Reauthentication Experience

Reauthentication should be:

* **Explicit** — users understand that access needs to be restored
* **Non-destructive** — existing configuration remains intact
* **Predictable** — there is a clear recovery path

Avoid silently failing or repeatedly retrying invalid tokens.

***

### 5. Log and Observe Failures

Your integration should log:

* Token refresh failures
* Detection of token expiry or revocation
* Reauthentication triggers

These logs are essential for diagnosing authentication issues and supporting users effectively.

***

### 6. Align With Integration Design Requirements

This how-to describes **how** to respond when tokens expire or are revoked.

For design-level requirements, see [Handling Refresh Token Expiry or Revocation](/docs/current/integration-design/auth/oauth/token-lifecycle/integration-design-auth-oauth-refresh-token-expiry-revocation)

***

## Result

After completing these steps:

* Invalid or revoked tokens are detected reliably
* API calls stop safely when access is no longer authorised
* Users are guided through a clean reauthentication flow
* Integrations recover predictably without data loss

***

## What Comes Next?

<WhatComesNext href="/docs/current/guides/oauth-workflow-guide#6-handle-token-expiry-or-revocation">
  Go back to guide
</WhatComesNext>

***

<div className="text-xs uppercase" style={{ fontVariant: 'small-caps' }}>
  this how-to is part of:
</div>

<div className="mt-4 flex flex-wrap gap-2">
  <a
    href="/docs/current/guides/oauth-workflow-guide"
    className="inline-flex items-center rounded-full border border-gray-300 dark:border-gray-600 
px-3 py-1 text-xs font-medium 
bg-white dark:bg-[#1f262b] text-black dark:text-white
hover:bg-gray-100 dark:hover:bg-[#2b2f33]
transition-colors"
  >
    OAuth 2.0 Setup Workflow Guide (Manual Token Lifecycle)
  </a>
</div>

***

## Related Reading

* [Token Lifecycle](/docs/current/integration-design/auth/oauth/token-lifecycle/integration-design-auth-oauth-token-overview)
* [OAuth 2.0 Client Registration](/docs/current/integration-design/auth/oauth/getting-set-up/oauth-client-registration) – Step-by-step details of required fields, credentials, and redirect URIs.
* [OAuth 2.0 Client Configuration](/docs/current/integration-design/auth/oauth/getting-set-up/oauth-client-configuration) – How to configure your client with correct endpoints, PKCE, and authentication methods.
* [PKCE and Secured Patterns](/docs/current/integration-design/auth/oauth/implementing-oauth/integration-design-auth-oauth-pkce-and-secured-patterns) – Security requirements for public clients.

***
