- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2020 06:39 PM
Hi all,
I'm trying to set up a scheduled REST call between ServiceNow and Azure but I can't work out how to get the authentication token so I can use that to complete the request as expected. This is the code I'm using at the moment:
var tenantID = '{tenantID}';
var clientID = '{clientID}';
var subscriptionID = '{subscriptionID}';
var clientSec = '{clientSecret}';
var request = new sn_ws.RESTMessageV2();
request.setEndpoint('https://login.microsoftonline.com/'+tenantID+'/oauth2/v2.0/authorize?client_id='+clientID+'&response_type=id_token&scope=openid&response_mode=fragment&state=12345&nonce=678910');
request.setHttpMethod('POST');
var response = request.execute();
And it's just coming back with the response body as "undefined" and it blats in a HTML page for logging in, so I assume that's wrong.
I've also tried the following:
var tenantID = '{tenantID}';
var clientID = '{clientID}';
var subscriptionID = '{subscriptionID}';
var clientSec = '{clientSecret}';
var request = new sn_ws.RESTMessageV2();
request.setEndpoint('https://login.microsoftonline.com/'+tenantID+'/oauth2/token');
request.setHttpMethod('POST');
request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
var reqBody = "{'grant_type':'client_credentials', 'client_id':"+ clientID +",'client_secret':"+ clientSec+",'resource':'https://management.azure.com'}";
request.body = reqBody;
var response = request.execute();
But that failed with the following error (some details have been removed):
*** Script: {"error":"invalid_request","
error_description":"AADSTS900144:The request body must contain the
following parameter: 'grant_type'.\r\nTrace ID: {}\r\nCorrelation ID: {}\r\n
Timestamp: 2020-07-24 07:52:48Z","error_codes":[900144],"
timestamp":"2020-07-24 07:52:48Z","trace_id":"{}
","correlation_id":"{}","error_uri":"
https://login.microsoftonline.com/error?code=900144"}
I've spoken to some of our internal peeps and we can't work out how to get it working. Can anyone provide any assistance?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2020 06:47 PM
Basically what I can see here is that it's OAUTH token issue. Following links will help:
Sudhanshu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2020 06:47 PM
Basically what I can see here is that it's OAUTH token issue. Following links will help:
Sudhanshu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2020 01:17 AM
The first link helped immensely. Thanks Sudhanshu! 🙂 I've got it working now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2020 01:32 AM
Pleasure Moira!!