How to retrive the oauth token an by script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
Hello everyone,
I have created and configured my Oauth provider, and when I go in the OAuth 2.0 Credentials, I am able to retrieve my token.
I wanted to retrieve this token by script in order to be able to perform some powershell action on my exchange server.
But i can't get my token by script, this is my current script but no luck
var SCOPE = "https://outlook.office365.com/.default" ;
var profileId = 'XXX';
// createing request
var client = new sn_auth.GlideOAuthClient();
var request = new sn_auth.GlideOAuthClientRequest();
request.setProfile(profileId);
request.setGrantType('client_credentials');
request.setScope(SCOPE);
var resp = client.requestToken(request);
if (!resp || !resp.isValid()) {
gs.error('OAuth error: ' + (resp ? resp.getErrorMessage() : 'no response'));
}
var token = resp.getAccessToken();
gs.info('Token OK, expires in ' + resp.getExpiresIn() + 's');
Does anyone know how I could do it ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Hi @J_r_my1
Can you try this approach to retrieve token.
var oauthClient = new sn_auth.GlideOAuthClient();
var tokenResult = oauthClient.getAccessToken('Your_OAuth_Profile_Name');
if (tokenResult.access_token) {
var accessToken = tokenResult.access_token;
gs.info("Access token successfully retrieved: " + accessToken);
} else {
gs.error("Failed to retrieve access token");
}
Thanks,
Vignesh
"If this solution resolves your issue, kindly mark it as correct."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Doesn't work as well, i also tried the method
oauthClient.getToken();
But it doesn't work.