Configure Custom Refresh for Access Tokens for Accounts when using OAuth 2.0 Authentication
Tags: authentication, oauth2, tutorial, integration
Published: 2021-09-10 08:45:20

---
title: Configure Custom Refresh for Access Tokens for Accounts when using OAuth 2.0 Authentication
published: true
date: 2021-05-18 07:47:45 UTC
tags: #authentication, #oauth2, #tutorial, #integration
canonical_url: https://tech.forums.softwareag.com/t/configure-custom-refresh-for-access-tokens-for-accounts-when-using-oauth-2-0-authentication/241437
---

OAuth 2.0 access tokens typically have a very limited lifetime. To enable [webMethods.io](http://webMethods.io) Integration to refresh a configured access token, you must configure **Refresh Access Token** to `true` and **Session Management** to `fixed` or `auto`.

To use the Out-of-Box refresh implementations offered by [webMethods.io](http://webMethods.io) Integration, configure **Refresh URL Request** as _URL Query String_ or _Body Query String_ along with appropriate values for the fields Consumer ID, Consumer Secret, Refresh Token, Refresh URL, and Access Token. This option can be used if the API provider adheres to the standard implementation of the Refresh grant type as described by the OAuth 2.0 Authorization Framework specification.

The following example provides you information on how to implement and configure a custom refresh mechanism for Accounts using [webMethods.io](http://webMethods.io) Integration.

#### Before you begin

- When using the REST connector, if you are using Google API services, then you need to have a working Google account to log into the Google Cloud console to obtain the access token for OAuth 2.0 authorization.
- You need to have access permission for Google APIs.
- When using the endpoint target (Server URL) to initiate communication with the SaaS provider, for example, Twitter, the endpoint is [https://api.twitter.com/1](https://api.twitter.com/1). To get the endpoint, go through the SaaS connector documentation available on the internet.
- When using Custom Connector, every back end provides its own authentication mechanism. Get the authentication details from the backend documentation.
- You need to have a relevant Google connector app in Google Cloud Platform to retrieve its Client ID and Client Secret if using any Google APIs.

#### Basic Flow

Before you try to configure a refresh token callback for a REST connector, you must have the following configurations (Step 1 - Step 3) completed on the Accounts configuration page:
1. Get the endpoint target (Server URL) for the connection configuration. For example, ([https://api.twitter.com/1.1](https://api.twitter.com/1.1)).
![refresh_oauth3](https://aws1.discourse-cdn.com/techcommunity/original/3X/5/6/560cbe0374fa202e1a03a054180471d8d129c698.png)
2. Get the Consumer ID and Consumer Secret issued to the client to identify itself to the authorization server. Consumer Secret is a secret matching to the client identifier.
![refresh_oauth4](https://aws1.discourse-cdn.com/techcommunity/original/3X/f/2/f2bd1285c2630dff3d152b439180254f4f898fb5.png)
3. Configure the Session Management parameters to determine at what intervals the access token would be considered for a refresh.  
The access token is refreshed during the next immediate execution after the determined interval. Session expiration is handled according to the setting of the Session Management property in your configuration. To refresh the ‘Access Token’ automatically, set the Session Management to either _fixed_ or _auto_. The Timeout value should be based on the back-end settings.
**Note:** If Session Management is set to none, then the access token will not be refreshed.
![refresh_oauth5](https://aws1.discourse-cdn.com/techcommunity/original/3X/3/b/3bbc3fe5568cef73e6267a770f3caa89186dc5a0.png)
4. Select Refresh URL Request field as Refresh token callback service to configure a custom refresh implementation. This field is available only if the OAuth v2.0 authentication type is selected.
![refresh_oauth6](https://aws1.discourse-cdn.com/techcommunity/original/3X/a/b/ab0cdd6598f9ef1766967443bdbc3c1f75210c03.png)
When you select this option, you must specify the FlowService name in the **Refresh token callback service** field. This is a service that needs to be implemented by a user. The **Refresh token callback service** option allows you to create a FlowService, which will be executed when the access token has expired or is not valid. You can view the link of the same FlowService on the **REST Connectors** page.
5. Click the custom callback FlowService name in the **REST Connectors** page to create a new FlowService.
![refresh_oauth7](https://aws1.discourse-cdn.com/techcommunity/original/3X/0/8/085dfe28ed3d58aa76585c3a695a3d2560c24b41.png)
You must add the implementation for refreshing the access token in the Callback FlowService.
The FlowService adhere to the specification with the input and output parameters shown below:
These are the inputs that would be provided to the Custom callback FlowService implementation by [webMethods.io](http://webMethods.io) Integration. Values will correspond to the current values of these fields in the account configuration
![refresh_oauth1](https://aws1.discourse-cdn.com/techcommunity/original/3X/5/1/51f2061f17593c52d847e87e324d57811e55d48e.png)
These are the output expected by [webMethods.io](http://webMethods.io) Integration. The values returned for these fields will determine the inputs for the subsequent API and refresh execution.
![refresh_oauth2](https://aws1.discourse-cdn.com/techcommunity/original/3X/f/e/fe42dc1e711542d1d52dd5265cdb571ede04fca7.png)

* **access\_token** - The access token issued by the authorization server, applicable for subsequent API and refresh executions.
* **token\_type** - The type of the token issued. For example, `bearer`.
* **expires\_in** - The lifetime in seconds of the access token. For example, the value _3600_ denotes that the access token will expire in one hour from the time the response was generated. Relevant for auto session management where expiry interval returned by API provider is given precedence.
* **refresh\_token** - The refresh token to be used for subsequent refresh execution.
* **scope** - (Optional) If identical to the scope requested by the client; else, REQUIRED
* **errorResponse** - The details of the error in refresh execution.
The newly created FlowService will generate an access token that is mapped to the access token field in the output signature.

[Read full topic](https://tech.forums.softwareag.com/t/configure-custom-refresh-for-access-tokens-for-accounts-when-using-oauth-2-0-authentication/241437)