Solarion
Honorary Master
- Joined
- Nov 14, 2012
- Messages
- 28,050
- Reaction score
- 17,804
Hi guys. I have a question on the MVC side regarding authentication. If you could please offer some clarity.
It is in regard to sending the token back to the API on a request for resources.
Now I have been doing it this way up till now; storing the token in a session object: http://binaryintellect.net/articles/db752e63-8e07-4760-b7f2-a882e67636ce.aspx
Then whenever I send a request to the API I access and send the token as such:
ServiceClient
What has led me to start questioning my own reality was when I was doing some digging around about accessing tokens and found something related to this; requesting the jwt via a cookie object. After several attempts to do it this way, all I kept getting back was the AntiForgery token when doing this way, NOT the actual token from the API.
Middleware
ServiceClient
As I mentioned this is only giving me back the AntiForgery token. Is my previous way of storing in sessions correct or am I doing something critically wrong? Please advise!
It is in regard to sending the token back to the API on a request for resources.
Now I have been doing it this way up till now; storing the token in a session object: http://binaryintellect.net/articles/db752e63-8e07-4760-b7f2-a882e67636ce.aspx
Then whenever I send a request to the API I access and send the token as such:
ServiceClient
What has led me to start questioning my own reality was when I was doing some digging around about accessing tokens and found something related to this; requesting the jwt via a cookie object. After several attempts to do it this way, all I kept getting back was the AntiForgery token when doing this way, NOT the actual token from the API.
Middleware
Code:
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie("Cookies", options =>
{
options.LoginPath = "/Account/Login";
options.LogoutPath = "/Account/Logout";
options.AccessDeniedPath = "/Account/AccessDenied";
options.ReturnUrlParameter = "ReturnUrl";
options.Cookie.Name = "bearer_token";
});
ServiceClient
Code:
httpContextAccessor.HttpContext.Request.Cookies["bearer_token"];
As I mentioned this is only giving me back the AntiForgery token. Is my previous way of storing in sessions correct or am I doing something critically wrong? Please advise!
Last edited: