I have the following Java Spring REST API method:
@RequestMapping(value = "/login", method = RequestMethod.POST)
public ResponseEntity login(@RequestBody LoginRequest request) {
request.getSession(true);
LoginResponse res = this.authService.login(request);
return new ResponseEntity<>(res, HttpStatus.OK);
}
When called using Postman or from a FireFox browser, I can clearly see the "Set-Cookie" header:
Yet, when I'm using console.log
to print the response in Angular, I don't see this header:
This is the REST call in Angular:
this.http.post<Login>(this.url, this.loginRequest, {
headers: AuthService.getHeaders(),
observe: 'response',
withCredentials: true
}).subscribe(
response => {
console.log(response);
});
I did add withCredentials: true
and observe: 'response'
to the request call as suggested, and I do get the whole response, but without the cookie.
What I want to do is to get a cookie after a successful login, which will be delivered with any request afterwards for authentication in the server.
Thanks for the help!
document.cookie
) This is most likely a security feature of the browser to prevent cookie stealing from other domains and isn't passed on to JavaScript (along with that some cookie values won't be accessible because they have thehttponly
setting). – Daniel W Strimpel