I\'m dealing with HttpClient in Angular 5, the problem is the cookie sent by the server during login process, it seems that Angular is ignoring it because next request with
Finally I was able to made it work!!
The solution was in post request,
Maybe I'm wrong but it seems like RequestOptions class was deprecated in Angular 5.0.0, so after several attempts hit the right configuration, Here is the method fixed
/** POST: add a new hero to the server */
makeLogin (us:string, password:string): Observable<any> {
let enco : any = new HttpHeaders()
.set('Content-Type', 'application/x-www-form-urlencoded');
let body : any = new HttpParams()
.set('username', us)
.set('password', password);
return this.http.post(this.urlServicioLogin,
body.toString(),
{
headers: enco,withCredentials:true
}
);
}
Now with withCredentials true I can see in browsers the cookie being set, and after that send it with subsequent requests.
Note: If the app has to consume a rest service where auth is made with cookies ALL interactions with backend will need withCredentials flag set to true.