sn_auth.GlideOAuthClient() help
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2025 10:45 PM
HI Team,
Can you please help me here :-
var oAuthClient = new sn_auth.GlideOAuthClient();
var requestorId = what should be the value
var entityProfile = what should be the value
Thank You,
Ketan
6 REPLIES 6
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2025 02:02 AM
Could you please provide the sample code
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2025 02:19 AM
Something like this
I believe I have answered your question and you can take it from here
var oAuthClient = new sn_auth.GlideOAuthClient();
var requestor_context = 'oauth_2_0_credentials';
var requestor_id = ''; // sys_id of oauth_2_0_credentials record
var oauth_profile_id = ''; // profile ID [sys_id of 'OAuth Entity Profiles' (oauth_entity_profile) record in OAUTH registry record]
var clientId = ''; // your client id
var clientSecret = ''; // your client secret
var oauthAppRegistryName = ''; // your OAuth app registry name
var params = {
grant_type: "password",
client_id: clientId,
client_secret: clientSecret,
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(oauthAppRegistryName, text);
var token = tokenResponse.getToken();
if (token) {
var access_token = token.getAccessToken();
if (access_token) {
gs.info('access token is' + access_token);
} else {
gs.info('OAuth token request failed.');
}
} else {
gs.error('OAuth token request failed.');
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Regards,
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader