function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Christopher M FaniChristopher M Fani 

Using Auth Provider / Named Credentials with MS Graph API / SP Online

Running into an issue integrating with O365 SP Online.  I have been able to successfully authenticate and use the Graph API with the 2 step Authorization Grant flow in Apex. 

I have been trying to replicate using an Auth Provider and Named credentials.  I have setup the AP and authenticated the Named Credential.  The Bearer token is inserted into the header of the API call, but the response is Invalid Token.  Looking to see if anyone has been able to get this working.            
ujwal thejaujwal theja
Hi Christopher,

Have you added clientid and client secret from connected app to AP.

Thanks,
Ujwal K
Christopher M FaniChristopher M Fani
Thanks for the reply. Yes, the Client ID and Secret have been added. The initialization URLs work just fine from the browser. Also, the Named Credential authenticates successfully as well. I redirected the request to a REST container to see the request headers and it contains a Bearer token. But, Azure is rejecting. Again, I have this working when managing the auth flow and tokens via Apex directly….I can auth and call the Graph APIs just fine. The purpose of the AP and Name Creds is to manage that for you and store the token securely.
Christopher M FaniChristopher M Fani
I was able to get this to work. The Authorize URL had a resource_type param in the URL. I removed this and the Graph API calls are working. From: Fani, Christopher Sent: Wednesday, May 8, 2019 9:56 AM To: 'reply' Subject: RE: [EXTERNAL] (Salesforce Developers): New reply to your question. Thanks for the reply. Yes, the Client ID and Secret have been added. The initialization URLs work just fine from the browser. Also, the Named Credential authenticates successfully as well. I redirected the request to a REST container to see the request headers and it contains a Bearer token. But, Azure is rejecting. Again, I have this working when managing the auth flow and tokens via Apex directly….I can auth and call the Graph APIs just fine. The purpose of the AP and Name Creds is to manage that for you and store the token securely.