Issue with Storing JWT in Cookies

Viewed 86

I have been trying to store the JWT I am getting from my OAuth2 server as a cookie in my React application and setting HttpOnly flag to true.

I am running a .NET Core backend and I am facing issues with reading the stored cookie on the server side. No matter what, I am always getting only 3 cookies which seem to be the standard ones using Request.Cookies.

2 of them start with ga and another one is a CookieConsent one. So I am not getting my custom cookies at all.

I have tried both axios and fetch with the same result.

1 Answers

After a few hours I finally figured out how to fix the issue thanks to Stefan for his comment.

What I did was to move my React app into my .NET project and use .NET's SPA extension to host it.

The issue was happening because of SameSite check with Cookies and although I was setting that value to .Lax/.None I still wasn't able to access my cookies.

Now because I am using a same domain for both my frontend and the API, I am able to read HttpOnly cookies correctly.

Related