Is it okay to pass Bearer token through script despite it deals automatically in REST message??

KM SN
Tera Expert

I have opted OAuth authentication in Rest message whenever I am calling the rest message automatically validates token if it expired it gets new token if not it will use the existed token.

 

But third party asking me to send bearer token separately through body or header? Is that works? Is it best practice sending bearer token again whenever making rest call?

 

How to get this bearer token when I am using client ID credentials method? 

 

 

 

12 REPLIES 12

@KM SN 

 

It's here in this video https://www.youtube.com/live/NyFooBktJNE?si=aB8FU9ppuYh7hfPT

 

Start at around 40:00 and full script is shown. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

@KM SN  Here, is exact info 

 

Automatically get a new OAuth Access Token When The Old One Expires (Unsupported Custom Scheduled Jo...


Actually easier is this :- 

 

var req = new sn_ws.RESTMessageV2();
req.setEndPoint( < OAUTh end point URL >);
req.setHttpMethod('POST');
req.setRequestHeader('content-type','application/x-www-form-urlencoded') 
req.setRequestBody(grant_type=" + grant_type + "&username=" + username + "&password="+encodeURI(pwd)+ "&client_id="+client_id+"+ "&client_secret="+client_secret));
var response = req.ExecuteAsync();
response.WaitForResponse(10);
var responseBody = response.getBody();
var obj = JSON.parse(responseBody);
gs.info('Token : "+obj.access_token);

 

If you can't go about getting the refresh token use this, get an access token and pass this. This could be easier and precise now @KM SN 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

@KM SN 

did they share how the request body will look like for you to pass the access token in request body?

your 1st step will be to get the Access token using OAuth endpoint of Azure

once you get that token you can then include that in body as per the format they shared.

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

@KM SN 

Thank you for marking my response as helpful.

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

Hello @KM SN 

 

Thanks for marking my response as helpful. Please accept solution if you found it valuable. This will help me be recognized for efforts and also help future readers understand full concept. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY