[SalesForce] 401 Unauthorized access while accessing Sahre Point through NTLM authentication(Windows authentication) from APEX

I was trying to callout Share point Service from apex using REST API.Which is having windows authentication which is of type NTLM. But i was getting 401 Unauthorized access.But i was able to access form SOAPUI and from browser.

Http objhttp;
HttpRequest req ;
HttpResponse res ;
objhttp = new Http();
req = new HttpRequest();
res = new HttpResponse();  
req.setMethod('GET');
req.setEndpoint('my end point url');
Blob headerValue = Blob.valueOf('domain"\"username'+':'+'password');
String authorizationHeader = 'NTLM '+EncodingUtil.base64Encode(headerValue);
system.debug('*** authorizationHeader '+authorizationHeader );
// Set the necessary Headers
req.setHeader('Authorization',authorizationHeader);
req.setHeader('Accept','application/vnd.cpc.authreturn+xml');
req.setHeader('Content-type','application/vnd.cpc.authreturn+xml; charset=UTF-8');
req.setHeader('Accept-Language', 'en-CA');
req.setHeader('Content-Length', '200');
req.setTimeout(120000);
system.debug('*** req is '+req);
try {
res = objhttp.send(req);
System.debug('res values in req: '+ res);
response=res.getBody();
system.debug('*** response is '+response);
}
catch(System.CalloutException e) {
System.debug('Callout error : '+ e);
 }

This was the code I am using to do call outs.Previously when the authentication is 'basic' i am getting proper response, but now when it changed to windows authentication by using 'NTLM' its giving 401 unauthorized error. But SOAPUI is giving proper response using 'NTLM'. Is there any possibility to call Sharepoint having windows authentication using this NTLM ..

Best Answer

It should first send you a challenge. Does it not even do that?

Have you checked this NTLM implementation in Apex? https://github.com/natewallace/ApexNTLM

Related Topic