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
Ryan Raymundo 1Ryan Raymundo 1 

Unable to get Header Basic Authorization from external API call

Hello everyone,
I have created an endpoint (@RestResource), made it public, and able to accept calls which works. Now I wanted to just add some simple authentication. Since the call is from another system webhook I dont have any control, I can only check the basic auth value and compare it before I process the JSON body. 

My issue is I cant get the basic authorization using this code: 
RestRequest req = RestContext.request;
        if (req.headers.get('Authorization') == null)
        {
            // always goes here
            authorizationHeaderValue = 'Null';
        }

Any ideas? Thanks in advance!
VinayVinay (Salesforce Developers) 
Hi Ryan,

As per my understanding,  salesforce does not allow access to the authorization header if you are using the a salesforce login with OAuth use UserInfo.getSessionId() to get the authorization data.

Thanks,
Ryan Raymundo 1Ryan Raymundo 1
Hi Vinay, thanks for your response but it's not using the login. It is a webhook and I want to validate if it has the correct auth header before I process it.