In my angular project, I have a basic signin page where user enters their email and password and on submit, I send the email and password to server and receive a response that contains setcookie which I have to use in the next page which is two-factor authentication. I want to use that cookie in another API call (for two-factor authentication) but I don't know how.
This is my userLogin
API call:
userLogin(formdata: Login ): Observable<any> {
return this.http.post
(this.ServerUrl + 'Account/login', formdata, { headers: new HttpHeaders({'accept': 'text/plain',
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + this.token,
}), observe: 'response' , withCredentials: true });
}
And this is the response cookies that i get from server: Cookies
And this is my user2fa
API call:
user2Fa(formdata: Factor ): Observable<any> {
return this.http.post
(this.ServerUrl + 'Account/twoFactorLogin', formdata, { headers: new HttpHeaders({'accept': 'text/plain',
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + this.token,
}), observe: 'response' , withCredentials: true });
}
You are unable to access the cookie from your Angular code are you? I had faced similar issues in the past but I did not require to make any changes in my code. I had to make some environment-specific changes.
I do not know the exact environment you are working with, but the following points might help you out with finding a solution:
Also, I would suggest you test your current set-up running the Angular application and check if the same behavior is seen.