The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Microsoft Graph API - Accessing token from credential alias

Lyndsey2
Kilo Explorer

Hello,

I am trying to access the Microsoft Graph API via REST step in action designer but am having trouble passing the token into my header. I have already done the following:

  • Registered my application in Azure and confirmed app is assigned the appropriate roles and permissions.
  • Registered this within ServiceNow application registry and defined oAuth entity profiles and scopes. (default and offline_access)
    • It's worth noting that I set the Default grant type as Resource owner password credentials so I can authenticate and post to endpoints under a service account. After much research, this is the best solution for my requirements.
  • Created a new credential alias with a connection and credential. Within that credential, I am able to successfully "Get oAuth token". The expiration date is a time far into the future. I confirmed this refresh token exists in oauth_credential table.

I've spent many hours to be sure the parts above are set up correctly. I can successfully the endpoints I need to use via an outbound REST message. My problem is when I try to call this API via REST Step in an action within Flow Designer.

As you can see in the setup below, I have it set up under my connection alias that has the oauth token. I am using the exact script listed on the Microsoft website to post to teams. (Please note, I do not want to use the OOTB teams actions for functionality reasons) 

find_real_file.png

 

When I test this action, I get the error shown below:

{
  "error": {
    "code": "InvalidAuthenticationToken",
    "message": "Access token is empty.",
    "innerError": {
      "date": "2021-04-06T20:22:11",
      "request-id": "24ab03xxx",
      "client-request-id": "24abxxxxx"
    }  }}

After rereading the Microsoft documentation, I noticed the header "Authorization: Bearer {code}" Is required. How can I obtain the oAuth token from my connection alias to put into this header? It doesn't seem like a simple table lookup since it is encrypted in the oauth_credential table. I saw this this Flow Designer & IntegrationHub Lab and it looks like I may need to set up something similar to the "Connection Attribute" they set up within the Alias so that I can have a data pill of the token to drag it into my header in REST step. I have no idea where to go from here or how to grab the data after running the "get oauth token" link. Where do I go from here to be able to transfer the oAuth token from my alias to the REST step in Action? What am I doing wrong?

find_real_file.png

1 ACCEPTED SOLUTION

Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

Hi,

You should be able to use the credential value like this. Remember to put in "Bearer " first since the value only holds the token and not "Bearer ". also don't forget the whitespace after it as well.

 

find_real_file.png

//Göran
Feel free to connect:
LinkedIn
Subscribe to my YouTube Channel
or look at my Book: The Witch Doctor's Guide To ServiceNow

View solution in original post

4 REPLIES 4

Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

Hi,

You should be able to use the credential value like this. Remember to put in "Bearer " first since the value only holds the token and not "Bearer ". also don't forget the whitespace after it as well.

 

find_real_file.png

//Göran
Feel free to connect:
LinkedIn
Subscribe to my YouTube Channel
or look at my Book: The Witch Doctor's Guide To ServiceNow

Thank you very much Göran! I swear I had tried this before I must have done something wrong. You just saved me many moons of stress!

 

Lyndsey2
Kilo Explorer

Also I think another modification I needed to make was in the Application Registry, set the OAuth API Script to OAuthUtil or a script of your choosing.

find_real_file.png

Justin Scheich
Tera Guru

Hello, 
I am trying to set this up for a JAMF integration since we are not licensed for the service graph connector and the spoke does not support bearer tokens. 
When attempting to add the credential value, it returns a blank value. 
I have also tried entering the API key directly from the oauth record however this returns an invalid token as the token is updated during the rest call. 

Any idea why the credential would be returning no value?