Smartsheet Oauth2.0 GlideOAuthStringMap

Vinayak Belgaon
Mega Guru
Mega Guru

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'
};

 

16 REPLIES 16

mattparr
Kilo Contributor

Hey, did you get anywhere with this?
I was hoping to be able to modify my request to change the client_id in a client_credentials flow at run time.

I get the same thing for requestParamMap... eg nothing.

nope, trying hard. Also do check for Scopes in your case it might work.

iwai
Giga Sage

Hello.
The results of my research and analysis are as follows.

//Analysis results
object GlideOAuthStringMap
function constructor
function get
function getKeys
function isScopedObject
function put
function remove

//Example
var strKeys = ''+requestParamMap.getKeys();
if(strKeys){
    var keys = strKeys.split(',');
    for(var i = 0; i < keys.length; i++){
        gs.info(''+keys[i]+': '+ requestParamMap.get(keys[i]));
        //requestParamMap.put(keys[i],value);
    }
}

 
var paramMap = accessTokenResponse.getparameters();

paramMap is "GlideOAuthStringMap".