How to set state parameter for OAuth with valid ascii characters instead of a random number generated out of the boxDescriptionHow to set state parameter for OAuth with valid ascii characters instead of a random number generated out of the box Please note this is just a sample script for reference, and counts as an unsupported customisation. Any further customization should be made referring to ServiceNow documentation for OAuth client libraries.InstructionsSome Endpoints require State Parameter to be just ascii character during OAuth instead of out of the box which generates a random number , which is sometimes a -ve number. To achieve this we need to do the following: A.Intercept OAuth, auth code request and add/update a parameter and add login in the preprocessAuthCode() function B. The OAuth code when it initializes keeps the State in the session, after we generate the state , store the new value in the session C. Make sure OAuth Provider has "OAuth API Script" Set the new Script Include 'OAuthCustomASCIIChar' https://instance.service-now.com/nav_to.do?uri=oauth_entity.do?sys_id=<sys_id>%26sysparm_view=oauth_provider Create a new Script include Script include : OAuthCustomASCIIChar var OAuthCustomASCIIChar = Class.create();OAuthCustomASCIIChar.prototype = Object.extendsObject(OAuthUtil, {initialize: function() {this.ns_state = this.getRandomString();},preprocessAuthCode: function(requestParamMap) {gs.getSession().putProperty('oauth_state_key', this.ns_state);requestParamMap.put('state', this.ns_state);},preprocessAccessToken: function(requestParamMap) {},interceptRequestParameters : function(requestParamMap) {this.preprocessAccessToken(requestParamMap);},parseTokenResponse: function(accessTokenResponse) {this.postprocessAccessToken(accessTokenResponse);},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)paramMap.put(param, tokenResponse[param].toString());}},getRandomString: function() {var available = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";var answer = "";while (answer.length != 24) {answer += available.charAt(Math.floor(Math.random() * available.length));}return answer;},type: 'OAuthCustomASCIIChar'});