Script for automatically updating Managed Oauth tokens in oauth_credential
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-07-2019 02:42 AM
Hello,
I am trying to automatize the refreshing of Oauth tokens that I use in the REST Messages, so I don't have to manually trigger it once the refresh token expires.
I know the Access and Refresh token is stored in the oauth_credential. Can someone help me find a script that checks if they expire and if they do generate a new one ?
Thank you !
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-07-2019 03:31 AM
I don't have any script handy, but please let me know if the following option work or not.
You can create a script include function to call the outbound Rest Message to generate token
Set a variable to timeout value.
If the Rest Message expiry time is less than the time out value, you can proceed with your requirement
Else
Call the function calling Rest Message to generate a new token recursively.
In this option, i didn't consider session management. If you need session management, then need to consider caching.
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-10-2019 02:05 AM
thank you for the idea !
Can you tell me a bit more about how the REST message for the token should be set up so that it takes into consideration the access/refresh tokens lifespans ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-10-2019 02:23 AM
What i did was:
1) Created an outbound Rest Message with end point to the OAuth URL ('https://instance/oauth2/token') and method POST
2) Added HTTP Headers:
- Authorization : Value is Basic (You need to base64 encode clientId:clientsecret).
- Content-type:multipart/form-data
3) Added HTTP query parameter:
- grant_type:client_credentials.
which will give a response with token_type,access_token and expires_in data.
4) Created a script include to call this rest message as per the above comment.
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-11-2019 03:42 AM
Thank you !
Can you please clarify a couple of things to me please.
In the Endpoint shouldn't it be more like https://instance/oauth_token.do ?
Can you please explain to me a bit how should I make the authorization header, I should just introduce "clientid:clientsecret" - in base 64 ?
and in this scenario where would it take the username and password from ? I tried a couple of tests but i kept receiving a access denied error, bad username/password ?