Update an OAuth 2.0 access token from a service
Last updated
Was this helpful?
Last updated
Was this helpful?
An access token stored as a can be updated from a . This can be used to refresh the token, either on demand from the , from , or using a .
Before you create this service:
You must first create the where the access token should be stored. The secret must be environment-specific and cannot be locked.
The or that runs the service must have a role that has been granted the Update Secret from Service > SECRET_NAME
.
You should have the documentation for the external API available, as you will need to construct a web request to fetch the new access token and map the token sent in the response.
To see how to run the service on a set schedule, for example every 24 hours, see Run a service on a schedule.
If you have an existing service that you use for integration with the external API, you can open that service.
If you do not have an existing service, or if you you want to create a new service specifically to update the secret, create a new service.
Under , click New Service.
Enter a name.
Click Create Service.
When called, the endpoint will trigger an action that runs a to an external API to refresh the token. The token returned is temporarily stored in a Service variable before the secret is updated.
In the service:
Add a new endpoint or use the default endpoint that is created.
Enter a Name.
Verify that GET
is selected under Methods.
Go to the Data tab.
Click Service Variables in the list of data sources.
Click Add Runtime Property.
Enter a name. This variable will be used for temporarily storing the token.
Go to the Actions tab.
Add a new action.
For the Data Source property, select Service Variables
.
Under Values on update, set the token Service variable to null. This ensures the value is reset every time the service is run.
Configure the request to fetch a new access token as per the format required by the external API.
Add a Result Mapping.
For the Data Source property, select Service variables
.
Map the access token key in the response to the token Service variable.
For the Secret property, select the secret you have created to store the access token.
For the Value property, bind it to the Service variable containing the access token.
Go to the Endpoints tab.
For the Process Action property, select the action you just created.
Check Enable Log to create a entry every time the endpoint is run.
Add an .
Add an .
Add an .
For the Condition property, create a that checks if the token Service variable has a value.
Inside the If action node, add an .
Test the service to ensure the access token is returned and the secret is updated. Remember that the or that runs the service must have a role that has been granted the Update Secret from Service > SECRET_NAME
.