angularasp.net-web-apihttp-status-code-401ntlm-authentication

How to pass NTLM credentials using angular http post call?


I am working on localhost where angular and web api using 2 different ports that's causing issue now.

I am trying to call web api c# from angular like this

this.http.post<AccessToken>(`${this.url}/api/Home/Eid/?code=12345sfffs`,{headers:this.httpHeaders})
       .pipe(Response => {
         console.log("hi");
         console.log(Response);
        return Response;
        }); ```

But I am getting below error

Failed to load resource: the server responded with a status of 401 (Unauthorized)

When I tried in postman also I got same 401 error and later I fixed by adding NTLM credentials in postman to get 200 response.

But how to pass NTLM credentials from angular post call? And why web api expecting for NTLM credentials?

Thanks in advance!


Solution

  • I have modified my angular post call to this

      return
     this.http.post<AccessToken>(`${this.url}/api/Home/Eid/?code=12345sfffs`,{headers:this.httpHeaders},{
    withCredentials: true })
            .pipe(Response => {
             console.log("hi");
             console.log(Response);
             return Response;
             });
    

    In Web API, I have modified web.config to this

    <httpProtocol>
          <customHeaders>       
            <add name="Access-Control-Allow-Origin" value="http://localhost:4200"/>               
            <add name="Access-Control-Allow-Credentials" value="true" />              
          </customHeaders>
        </httpProtocol>