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.