Smartsheet Oauth2.0 GlideOAuthStringMap

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2020 05:38 AM
Hello,
I am tying to integrate the Smartsheet application with servicenow using Oauth2.0 token. The issue i am facing is the the keyword in authorization code that the smartsheet is sending is not of access_token but of code example: https://<myinst>.com/oauth_redirect.do?code=dlhmqzuefidheafy&expires_in=599928&state=483270143
as per the "Live Coding Happy Hour" on youtube https://www.youtube.com/watch?v=6KPhLYIDchU i created a custom Script include to fetch the accesstoken response, but i am not able to the the parameters as per the video. The only function that is being called is the "preprocessAuthCode" but the arguments passed to is empty and the log shows as [object GlideOAuthStringMap], not able to find the documentation to it. Could anyone help with me parsing the parameters
below is the Script include i have written
var OAuthJSSmartSheet = Class.create();
OAuthJSSmartSheet.prototype = {
initialize: function() {
gs.info("testing init");
},
interceptRequestParameters: function(requestParamMap) {
// Add/Modify request parameters if needed
gs.info("testing interceptRequestParameters="+requestParamMap.toString());
this.preprocessAccessToken(requestParamMap);
},
parseTokenResponse: function(accessTokenResponse) {
gs.info("testing parseTokenResponse="+accessTokenResponse.toString());
try {
this.postprocessAccessToken(accessTokenResponse);
} catch (e) {
gs.info(e);
}
},
preprocessAuthCode: function(requestParamMap) {
gs.info("preprocessAuthCode=" + requestParamMap);
// gs.info("preprocessAuthCode=" + requestParamMap.getBody());
// gs.info("preprocessAuthCode=" + requestParamMap.getparameters());
// gs.info("preprocessAuthCode=" + requestParamMap.getContentType());
},
preprocessAccessToken: function(requestParamMap) {
gs.info("testing preprocessAccessToken=" + requestParamMap);
},
postprocessAccessToken: function(accessTokenResponse) {
gs.info("testing postprocessAccessToken=" + accessTokenResponse);
var contentType = accessTokenResponse.getContentType();
var contentBody = accessTokenResponse.getBody();
gs.info("testing=" + contentType);
gs.info("testing=" + contentBody);
/* 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());
}*/
},
type: 'OAuthJSSmartSheet'
};
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2021 12:57 PM
Thank you! This appears to be a functional workaround. I also received a response from Support that this has been documented in PRB1417633 and will be fixed in Quebec release. I'll check my PDI to confirm this is fixed in Quebec.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2024 05:21 PM
Log and Inspect Request Parameters:
- The main issue seems to be understanding and parsing the requestParamMap object correctly.
- Start by inspecting all available methods and properties of requestParamMap.
Modify Script to Extract Parameters:
- Use get() method to extract specific parameters.
- Convert the GlideOAuthStringMap object to a JSON string for better inspection.
Adjust Script Include:
- Enhance the preprocessAuthCode method to log detailed information about the requestParamMap.
Modified Script:
var OAuthJSSmartSheet = Class.create();
OAuthJSSmartSheet.prototype = {
initialize: function() {
gs.info("Initializing OAuthJSSmartSheet");
},
interceptRequestParameters: function(requestParamMap) {
gs.info("Intercept Request Parameters: " + requestParamMap.toString());
this.preprocessAccessToken(requestParamMap);
},
parseTokenResponse: function(accessTokenResponse) {
gs.info("Parse Token Response: " + accessTokenResponse.toString());
try {
this.postprocessAccessToken(accessTokenResponse);
} catch (e) {
gs.error("Error in parseTokenResponse: " + e);
}
},
preprocessAuthCode: function(requestParamMap) {
gs.info("Preprocess Auth Code: " + requestParamMap.toString());
// Attempt to log all parameters
var paramKeys = requestParamMap.getKeys();
for (var i = 0; i < paramKeys.size(); i++) {
var key = paramKeys.get(i);
var value = requestParamMap.get(key);
gs.info("Parameter Key: " + key + ", Value: " + value);
}
},
preprocessAccessToken: function(requestParamMap) {
gs.info("Preprocess Access Token: " + requestParamMap.toString());
},
postprocessAccessToken: function(accessTokenResponse) {
gs.info("Postprocess Access Token: " + accessTokenResponse);
var contentType = accessTokenResponse.getContentType();
var contentBody = accessTokenResponse.getBody();
gs.info("Content Type: " + contentType);
gs.info("Content Body: " + contentBody);
if (contentType && contentType.indexOf('application/json') != -1) {
var tokenResponse = (new global.JSON()).decode(accessTokenResponse.getBody());
var paramMap = accessTokenResponse.getParameters();
for (var param in tokenResponse) {
paramMap.put(param, tokenResponse[param].toString());
}
}
},
type: 'OAuthJSSmartSheet'
};