Unable to access WWW authentication header in $ http response in angular

Can someone tell me why the WWW-Authenticate header is null in the response, although I can see the WWW-Authenticate header string object in Chrome dev tools?

On the server side, I am doing the following to set the WWW-Authenticate header, and also set the correct headers for CORS:

res.setHeader('Access-Control-Allow-Origin', 'http://localhost:8080'); res.setHeader('Access-Control-Expose-Headers', 'WWW-Authenticate'); res.setHeader('WWW-Authenticate', JSON.stringify({ "token": "encryptedToken", "message": "encryptedMessage" })); 

I believe that I have correctly configured the header on the server side, because when I look at the Chrome Dev tools, I see the following in the “Response headers” section for the requested request.

Answer Header
Access-Control-Allow-Origin : http: // localhost: 8080
Access-Control-Expose-Headers : WWW-Authenticate
Connection : keep-alive
Date : Friday, May 15, 2015 13:48:29 GMT
ETag : W / "f7-1470611871"
WWW authentication : {"token": "encryptedToken", "message": "encryptedMessage"}
X-Powered-By : Express

HOWEVER, when I try to access the "WWW-Authenticate" header from a response, I get NULL.

 $http.get("http://localhost:4242/days") .then(function (response) { var AuthHeader = response.headers('WWW-Authenticate'); console.log (AuthHeader); // returns null }) 

Thanks for your help in advance!

+5
source share
1 answer

Ok ... So, after some trial and error, we figured it out. I had that the pre-configured X-to headers were outdated and irrelevant, but it looks like either the browser used in this case, or perhaps angular itself expects this.

Title Name Change:

 WWW-authenticate 

to

 X-WWW-authenticate 

Fixes a problem. If anyone can shed light on this, please do so.

In fact, referring to the first request here: Custom HTTP headers: naming conventions using X- are deprecated, and in fact the headers should just be "sensible" named 'sans any prefix. Perhaps rename:

 appName-authenticate 

Or similar practice.

+1
source

All Articles