Google API

pathat
Kilo Expert

Hello.

Has anybody experiment or developed a workflow in ServiceNow that calls out to Google using the Google APIs? I'm interested in hearing about your experiences and lessons learned.

I am interested in managing users in my Google domain via the Google Directory API.

20 REPLIES 20

I found something interesting digging around in the UI Action to fetch the token.   It appears that the error message is coming from there instead of from Google.   It is looking for the grant type of either 'password' or 'authorization_code', but it seems to be fetching the label instead of the value.   I stuck an 'alert(grantType);' line in after the fetch from g_scratchpad.grant_type, and it's returning the text "Resource Owner Password Credentials" or "Authorization Code" instead of the grant types it's looking for in the if statements further down.   I hard-coded 'authorization_code' and it got further.   Now I get a text box with what appear to be 3 sets of certificates.   According to the last note in the UI script, a client script is supposed to do something with it, but the only two I see are 'OnLoad' scripts.   I really don't see that this UI action is doing anything except opening a window to the URL that it builds.   How does this store an OAuth token?



function getOAuthTokenFromServiceProvider() {
// Clear status messages
g_form.clearMessages();

var oauthRequestorSysId = g_form.getUniqueValue();
var oauthProfileId = g_form.getValue('oauth2_profile');
var grantType = g_scratchpad.grant_type;
var oauthRequestorContext = 'sys_rest_message';

var oauth_initiator_url = '';
if (grantType === 'password') {
  oauth_initiator_url = '/oauth_password_input.do' +
  '?sysparm_oauth_requestor_context=' + oauthRequestorContext +
  '&sysparm_oauth_requestor=' + oauthRequestorSysId +
  '&sysparm_oauth_provider_profile=' + oauthProfileId;
 
} else if (grantType === 'authorization_code') {
  oauth_initiator_url = '/oauth_initiator.do' +
  '?oauth_requestor_context=' + oauthRequestorContext +
  '&oauth_requestor=' + oauthRequestorSysId +
  '&oauth_provider_profile=' + oauthProfileId +
  '&response_type=code';
 
} else {
  g_form.addErrorMessage('Unsupported OAuth grant type \'' + grantType + '\'.');
  return;
}

window.open(oauth_initiator_url, '', 'height=500,width=800'); // pops up window
return;
}


function parseAjaxResponse(response) {
// Do nothing as client script is performing the validation of the token.
}


Hi,



I have configured   google OAuth2.0 profile as mentioned in wiki and was successfully able to test google's REST API. I did it on Helsinki.


Also works from background script.


find_real_file.png


Hi Nilesh,



I have also got to this stage, but where do I go now to activate the functionality? When we log off and log back on we still see the original out of box login screen, rather than the 'Sign In with Google' Oauth consent screen. How do we get this to appear?



Thanks,



Charles


Even i have tried same and everything is working fine. I can get only details for my particular email id. if i am trying for some other email is. There is 404 error shows up. In that case, i have to logout my gmail account and again try to hit "GET OAUTH" button and sign in with different user to make it work. How to acheive this functionality somewhere in others forms or UI page, like when i hit a button or link a pop up should ask for gmail login and get access code and the remaining REST API code should process. Do any one have idea please share..?


Could you please let me know how you built the request body ?