OAuth token refresh question

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2018 07:51 AM
I am building my first integration (using REST and OAuth), and everything is working well, except that the OAuth token for the external system keeps expiring (it's set to 30 minutes).
I can refresh it manually by going to the REST Message, and using the Get Token UI Action, but obviously that isn't the real solution.
How can I refresh the token automatically (I am calling the REST Messages via business rule)?
- Labels:
-
Integrations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2018 09:22 AM
Server Side Code snippet to get a new Access Token when the previous Access token expires.
1. You need the Refresh toke to execute this code
2. You need the OAuth Applciation registry Name to get the new Access Token.
//GlideOAuthClientRequest
var clientRequest = new sn_auth.GlideOAuthClientRequest();
clientRequest.setGrantType('refresh_token');
clientRequest.setRefreshToken('INSERT_REFRESH_TOKEN');
//GlideOAuthClient
var client = new sn_auth.GlideOAuthClient();
//GlideOAuthClientResponse
var tokenResponse = client.requestTokenByRequest('INSERT_APPLICATION_REGISTRY_NAME', clientRequest);
//GlideOAuthToken
var token = tokenResponse.getToken();
gs.debug("Access Token: " + token.getAccessToken());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2019 04:39 PM
Is there a way to do this for Slack OAuth token? I am not able to get the refresh token for Slack
Thanks
Aman

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2020 11:01 AM
We ended up creating a system account in Salesforce, and using that. There were some other peculiarities having to do with API access to Salesforce that were causing the problems I was seeing. Also, because my integration triggers are all business rules, and flow designer/IntegrationHub are definitely better options, I'd likely build this completely differently now.
While I got my integration working, I don't consider myself enough of an expert on oAuth to give advice.