NTLM authentication using Angular2

2020-03-24 05:40发布

问题:

In my client web application, I need to authenticate with the server using ntlm protocol. While using Angular1, with the $http service get request, the browsers (chrome, edge) were doing all the 3 steps of the NTLM authentication by prompting user for username/password.

However, with Angular2, using the http service that comes with Angular2, the browser (chrome,edge) just return 401 and do not do the subsequent steps (they do not even prompt the user for credentials).

How do I make browser do the ntlm authentication for me while using Angular2 ? Please do not suggest the ntlm javascript library. I'm new to StackOverflow. If I haven't given sufficient info or repeated the question, sorry about that.

Thanks in Advance.

回答1:

I don't believe the problem is with NTLM or in your coding efforts. According to Anton Bessonov, a very reputable SO community member, some modules in Angular2 are just not production-ready yet, while Angular1 is a very stable code release, and my advise is to stick with Angular1 that for the foreseeable future. Ref: angular 1 vs angular 2 for new project



回答2:

"withCredentials" needs to set true in headers to make it work. My code is working now.

let options = new RequestOptions({ headers: headers, withCredentials: true });