Notifications

7 views

Description

If OAuth application registry authorization URL contains extra query parameter then URL is formatting wrongly with extra "?" mark in URL and throwing an error as 404 after we click on Get OAuth token in REST message  if you see the URL in the screenshot we can observer "?" mark after Authorize and after Service_now, here p=B2C_1_Service_now is extra query parameter in Authorization URL

Release or Environment

All

Cause

For example, your Authorization URL contains an extra query parameter as shown here "https://URL.domain.com/oauth2/v2.0/token?p=B2C_1_Service_Now" and when you click on Get OAuth Token in REST message request URL will get generated with extra "?" mark back to back which causes URL as invalid and throws 404 error as below, if you see the URL in the screenshot we can observer "?" mark after Authorize and after Service_now, here p=B2C_1_Service_now is extra query parameter in Authorization URL

 

 

Resolution

  • In order to resolve this issue, we need to remove that extra query parameter from Authorization URL and override by creating one script include which extends the OOB OAuthUtil script include as below.
var OAuthUtil1 = Class.create();
OAuthUtil1.prototype = Object.extendsObject(OAuthUtil, {
    preprocessAuthCode: function(requestParamMap) {
        requestParamMap.put("p", "B2C_1_Service_Now");
    },

	postprocessAccessToken: function(accessTokenResponse) {
        
        var contentType = accessTokenResponse.getContentType();
		if (contentType && contentType.indexOf('application/json') != -1) {
			var tokenResponse = (new global.JSON()).decode(accessTokenResponse.getBody());
			var paramMap = accessTokenResponse.getparameters();
			for (param in tokenResponse) {
				if (param == 'id_token') {
					paramMap.put("access_token", tokenResponse[param].toString());
				}
				else {
					paramMap.put(param, tokenResponse[param].toString());
				}
            }
		}
    },

    type: 'OAuthUtil1'
});


*Once the script is created then we can refer this custom script on OAuth API script field which will be available in that particular application registry

 

Article Information

Last Updated:2019-11-21 20:48:01
Published:2019-11-22