in my App (Angular 2 / Ionic 2) I implemented my own login/authentication. Basically it works like this: On login, username and password is being validated by the PHP backen
Just wanted to post the answer as it might help others: The solution as to set
Access-Control-Expose-Headers: Authorization
Then - frontend can read the Authorization header as well.
This answer helped me : link
It shows how to add it in the backend and how use it in the frontend
Java backend:
public void methodJava(HttpServletResponse response){
...
response.addHeader("access-control-expose-headers", "Authorization");
}
And access the header on angular like this:
return this.http
.get(<your url here for your backend>)
.map(res => console.log("cookie: " + res.headers.get("Authorization") )
}
That's not related to Angular. The problem is CORS limits headers by default and you do not see "Authorization" header when call CORS requests. So, adjust server to let it send Authorization header
Access-Control-Allow-Headers must be provided in response of OPTIONS request (pre-flight).
Access-Control-Expose-Headers must be provided in response of POST/GET request.
Access-Control-Expose-Headers: Authorization