OAuth Refresh Token Grant

On this page

Access tokens expire quickly. A Refresh TokenA credential that an application exchanges for a new access token without asking the user to log in again. lasts longer. Your app exchanges the refresh token for a new access token without asking the user to log in again.

To issue refresh tokens, turn on Generate refresh tokens and enable Refresh Token in Enabled grants on the OAuth tab of the Application. New Applications have both settings on. Your app then gets a refresh token from the token endpointThe OAuth 2.0 endpoint where an application exchanges a grant, such as an authorization code, for tokens. In FusionAuth, the token endpoint is /oauth2/token. when the request asks for the offline_access scope.

Exchange a Refresh Token for an Access Token#

Send the refresh token to the /oauth2/token endpoint with grant_type set to refresh_token. The example uses the refresh token from the Authorization Code grant example, and adds line breaks for readability.

Example HTTP Request
POST /oauth2/token HTTP/1.1
Host: piedpiper.fusionauth.io
Content-Type: application/x-www-form-urlencoded

client_id=06494b74-a796-4723-af44-1bdb96b48875
    &client_secret=example-client-secret-do-not-use
    &grant_type=refresh_token
    &refresh_token=ze9fi6Y9sMSf3yWp3aaO2w7AMav2MFdiMIi2GObrAi-i3248oo0jTQ

Replace example-client-secret-do-not-use with the Client secret from the OAuth tab of your Application.

FusionAuth returns a new access token:

Example JSON Response
{
  "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0ODUxNDA5ODQsImlhdCI6MTQ4NTEzNzM4NCwiaXNzIjoiYWNtZS5jb20iLCJzdWIiOiIyOWFjMGMxOC0wYjRhLTQyY2YtODJmYy0wM2Q1NzAzMThhMWQiLCJhcHBsaWNhdGlvbklkIjoiNzkxMDM3MzQtOTdhYi00ZDFhLWFmMzctZTAwNmQwNWQyOTUyIiwicm9sZXMiOltdfQ.Mp0Pcwsz5VECK11Kf2ZZNF_SMKu5CgBeLN9ZOP04kZo",
  "expires_in": 3600,
  "id_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0ODUxNDA5ODQsImlhdCI6MTQ4NTEzNzM4NCwiaXNzIjoiYWNtZS5jb20iLCJzdWIiOiIyOWFjMGMxOC0wYjRhLTQyY2YtODJmYy0wM2Q1NzAzMThhMWQiLCJhcHBsaWNhdGlvbklkIjoiNzkxMDM3MzQtOTdhYi00ZDFhLWFmMzctZTAwNmQwNWQyOTUyIiwicm9sZXMiOltdfQ.Mp0Pcwsz5VECK11Kf2ZZNF_SMKu5CgBeLN9ZOP04kZo",
  "token_type": "Bearer",
  "userId": "3b6d2f70-4821-4694-ac89-60333c9c4165"
}

For every field, see the Refresh Token grant request.

Inactive and Deleted Applications#

When you deactivate an Application, the Refresh Token grant for the Application fails with the following error:

Example JSON Error Response
{
  "error": "invalid_client",
  "error_reason": "invalid_client_id",
  "error_description": "client_id: 06494b74-a796-4723-af44-1bdb96b48875 is not valid."
}

FusionAuth keeps the refresh tokens of an inactive Application. After you reactivate the Application, the refresh tokens work again. A refresh token keeps aging while the Application is inactive, so the token can expire before you reactivate the Application.

When you permanently delete an Application, FusionAuth also deletes the refresh tokens of the Application. The Refresh Token grant then fails with the same error. To deactivate or delete an Application, see the Delete an Application API.