Update an OAuth 2.0 access token from a service
Before you create this service:
- 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.
- 1.Under Services, click New Service.
- 1.Enter a name.
- 2.Click Create Service.
When called, the endpoint will trigger an action that runs a Web request 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:
- 1.Add a new endpoint or use the default endpoint that is created.
- 2.Go to the Data tab.
- 1.Click Service Variables in the list of data sources.
- 2.Click Add Runtime Property.
- 3.Enter a name. This variable will be used for temporarily storing the token.
- 3.Go to the Actions tab.
- 1.Add a new action.
- 2.Add an Update object action node.
- 1.For the Data Source property, select
- 2.Under Values on update, set the token Service variable to null. This ensures the value is reset every time the service is run.
- 3.Add an Web request action node.
- 1.Configure the request to fetch a new access token as per the format required by the external API.
- 2.Add a Result Mapping.
- 3.For the Data Source property, select
- 4.Map the access token key in the response to the token Service variable.
- 5.Inside the If action node, add an Update secret action node.
- 1.For the Secret property, select the secret you have created to store the access token.
- 2.For the Value property, bind it to the Service variable containing the access token.
- 4.Go to the Endpoints tab.
- 1.For the Process Action property, select the action you just created.