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!
Seems that browsers do not share the cookies to the client if it's not https. I had to follow this guide in order to serve the application in https mode, and then I was able to see the cookie in the server side.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With