Adding Paramenters to OAuth Request via cloned & modified OAuthUtil script include?

Jason174
Tera Guru

The oauth endpoint I'm talking to requires another parameter to be added beyond what SN is already adding from the entity profile.

Can anyone help me with an example of how I should be modifying this portion to add my parameter to the request?

interceptRequestParameters : function(requestParamMap) {
		// Add/Modify request parameters if needed
		this.preprocessAccessToken(requestParamMap);
	},
4 REPLIES 4

Jason174
Tera Guru

Does the ServiceNow community have tumbleweed awards?

alexduan
Mega Contributor

When you extend OAuthUtil, make sure that the Script Include is a global application. I've tried using a scoped OAuth script, and it errors out.

The parameter map should be a String representation of the parameters that you will be sending. Try something like below:

interceptRequestParameters : function(requestParamMap) {
	var json = new JSON();
	// Add/Modify request parameters if needed
	var paramMap = json.decode(requestParamMap) || {};
	paramMap.anotherField = 'test';
	this.preprocessAccessToken(json.encode(paramMap));
},

Jan Sierens1
Tera Contributor

To make the REST token request work correctly for the Azure API, for example, I use this:

	interceptRequestParameters: function(requestParamMap) {
		// Add/Modify request parameters if needed
		requestParamMap.put('resource','https://management.core.windows.net/');
		this.preprocessAccessToken(requestParamMap);
	},

Thanks a bunch, this saved me a headache. The documentation just mentions the parameter is a string so decoding/encoding did not work for me.