So I implemented a custom Auth for Client Credentials flow using example from "https://lekkimworld.com/2021/05/07/custom-salesforce-auth-provider-for-microsoft-azure-client_credentials-flow" . I have oAuth working. My app requires that I pass Client_Id in the header. I'm trying to fetch client id using named credentials "{!$Credential.OAuthConsumerKey}". I have "Generate Authorization Header" unchecked and "Allow Merge Fields in HTTP Header" checked in the named credentials. I have the following code to invoke the API.
String Body = '{"message":"some text"}';
HttpRequest req = new HttpRequest();
req.setEndpoint('callout:mynamecred/abc');
req.setHeader('Content-Type', 'application/json');
req.setHeader('Accept', 'application/json');
req.setHeader('dummy','{!$Credential.OAuthConsumerKey}');
req.setMethod('POST');
req.setBody(Body);
Here's the header that I can see at the server
{
"VERSION": "HTTP/1.1",
"CONNECTION": "close",
"ACCEPT-ENCODING": "gzip",
"USER-AGENT": "SFDC-Callout/54.0",
"SFDC-STACK-DEPTH": "1",
"ACCEPT": "application/json",
"CONTENT-TYPE": "application/json",
"CACHE-CONTROL": "no-cache",
"PRAGMA": "no-cache",
"CDN-LOOP": "cloudflare",
"CONTENT-LENGTH": "23"
}
If I pass a hardcoded value in the header "dummy" , I can see it. I have a feeling , the custom Auth doesn't work with Merge fields. Any thoughts?
{!$Credential.OAuthConsumerKey}
. It might be able to merge the access token (not your use case).