HOWTO: Extend OAuth Token request to include resource parameter

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2023 02:25 AM - edited 06-22-2023 02:26 AM
Hi,
I was recently asked by a customer to include a resource parameter in the OAuth token request such that the request was directed at a specific API. The out of the box flow does not support this, so it is necessary to extend it, there was minimal documentation on how to do this, so I thought I would quickly detail it here.
1. Create a new Script Include extending OAuthUtil, if you are in a scoped app, remember to extend global.OAuthUtil
2. Within the new Script Include, create an override method for interceptRequestParameters and add your resource as a literal into it:-
interceptRequestParameters : function(requestParamMap) {
// Add the resource parm value
requestParamMap.put('resource','<your resource parameter value>');
this.preprocessAccessToken(requestParamMap);
},
Putting it all together you should have something like this (mine is in a scoped app so you will note global.OAuthUtil):-
var OAuthCustomUtil = Class.create();
OAuthCustomUtil.prototype = Object.extendsObject(global.OAuthUtil, {
interceptRequestParameters : function(requestParamMap) {
// Add the resource parm value
requestParamMap.put('resource','<your resource parameter value>');
this.preprocessAccessToken(requestParamMap);
},
type: 'OAuthCustomUtil'
});
3. Update the Application Registry, open the relevant OAuth provider record and update the OAuth API Script field with the reference to your new Script Include (in my example OAuthCustomUtil.
The only issue I have found is that you cannot pass the resource value into the script, it is a hard coded literal. If you have different resources for different providers, you will need to create an extending SI for each one.
Hope this helps someone in the future!
Richard
- 464 Views