Open URL in background (scheduled script or script include)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2022 09:20 AM
Hello experts,
I working on automation for OAuth authorization and i need to open URL from server site. Next this URL will redirect to new one and return parameter in URL link. Is it possible?
so steps should look like below:
1. open url in background
2. get parameter from redirected url
3. use parameter value in script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2022 10:09 AM
Is this for Oauth? If so, this isn't the best or more secure way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2022 10:56 AM
Hi Mike,
I’m aware that this is not the best way but this is the best option to avoid manual login to 3rd party to receive refresh token and to avoid multiple changes in integration.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2022 10:59 AM
Can you use this to generate the refresh token?
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0791131
Description
Below is sample script Script to retrieve Access and Refresh tokens using GlideOAuthClient libraries
This could be run from background scripts for testing purpose
Instructions
Code to retrieve Access token and Refresh Token:
var oAuthClient = new sn_auth.GlideOAuthClient();
var requestor_context = 'test';
var requestor_id = 'abc@xyz.com';
var oauth_profile_id = '43d6bab3db849f009a6ff9b61d961957'; // profile ID [sys_id of 'OAuth Entity Profiles' (oauth_entity_profile) record in OAUTH registry record]
var params = {grant_type:"password", username:'admin', password:'pwd', oauth_requestor_context:requestor_context, oauth_requestor:requestor_id, oauth_provider_profile:oauth_profile_id}; //
var json = new global.JSON();
var text = json.encode(params);
var tokenResponse = oAuthClient.requestToken('oAuth Test', text); //'oAuth Test' is the name of the OAuth application registry record (oauth_entity)
var token = tokenResponse.getToken();
var access_token = token.getAccessToken() ;
gs.log("AccessToken:" + access_token);
gs.log("AccessTokenExpiresIn:" + token.getExpiresIn());
gs.log(" RefreshToken:" + token.getRefreshToken());
Code to retrieve a new Access Token using Refresh token
var oAuthClient = new sn_auth.GlideOAuthClient();
var requestor_context = 'test';
var requestor_id = 'abc@xyz.com';
var oauth_profile_id = '43d6bab3db849f009a6ff9b61d961957'; // profile ID [sys_id of 'OAuth Entity Profiles' (oauth_entity_profile) record in OAUTH registry record]
var params = {grant_type:"refresh_token", refresh_token:"<value_of_refresh_token>", oauth_requestor_context:requestor_context, oauth_requestor:requestor_id, oauth_provider_profile:oauth_profile_id};
var json = new global.JSON();
var text = json.encode(params);
var tokenResponse = oAuthClient.requestToken('oAuth Test', text); //'oAuth Test' is the name of the OAuth application registry record (oauth_entity)
var token = tokenResponse.getToken();
var access_token = token.getAccessToken() ;
gs.log("AccessToken:" + access_token);
gs.log("AccessTokenExpiresIn:" + token.getExpiresIn());gs.log(" RefreshToken:" + token.getRefreshToken());
Making an outbound REST call with the retrieved token
// make the outbound REST call with the retrieved token
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2022 11:09 AM - edited 10-21-2022 11:09 AM
Hi Mike,
I tried to use this and with grant type: password I just receiving access token without refresh token