0

I have SalesForce and SharePoint connected on OAuth. I have created Sharepoint app-only, added it to Custom Auth provider and created namedcredentials which is showing as authenticated. Every blog post is saying that named credentials would take care of Authentication. But in my case it is giving me null Authorization header in my rest callout.And the REST callout is failing. Do we need to still pass the access token by receiving the Auth code from the OAuth-Only Initialization URL(from custom auth provider)?

req.setEndpoint('callout:SPSF/getbytitle(\''+String.escapeSingleQuotes(val)+'\')/items'); req.setMethod('GET'); //string token= GetJWT(); If I use this it works fine req.setHeader('Authorization', 'bearer ' + token); req.setHeader('Content-Type', 'application/json/x-www-form-urlencoded');

Because for REST callout we get the type auth. code from Oauthorize.aspx page.

enter image description here

0

If your authentication provider is working correctly (and it appears so based on Authenticated being the status), it has obtained a valid access token. You can then include the access token in your callout by using a merge field

req.setHeader('Authorization', 'Bearer {!$Credential.OAuthToken}');
0

Ok I have solved my issue. Don't need to pass the auth access token. Earlier I was checking to see why named creds was not handling the Authorization. It was because I was not passing the correct Headers. I have corrected the header from req.setHeader('Content-Type', 'application/json/x-www-form-urlencoded'); to req.setHeader('Content-Type', 'application/json');. Then I changed the Get to POST.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.