✅ Blazor Server does not store the cookie in the browser after login.
Hello people! I'm have some trouble trying to set up authorization in my blazor server app. I'm using an API made in .NET and Identity Framework to manage the authentication and authorization flow. I'm trying to consume it using my Blazor Server, although, when i try to login, it authenticate on the API, but the blazor server doesn't store the cookie that was sent by the API in the browser.
I've tried to set cors on the .NET API side, even in the blazor server too. But it still did not work as expected.
When i'm using the swagger to hit the login endpoint, it store normally on the browser, but through the blazor server it just ignore. I think it has to do with the cors, but i still don't know what is going on and how to solve it.
13 Replies
Do you force a reload of the browser the page after cookie was set?
Blazor server basically operates over one long http request, so it can't set cookies itself
I handle auth with razor pages that redirect back to the app after logging in
Yes, but it still not work.
That looks interesting. Can you tell me more about it?
Thats all there is to it really, it's just regular statically rendered pages
Post credentials to server, if they're good it signs them in and redirects them to the target page
Unknown User•4w ago
Message Not Public
Sign In & Join Server To View
My solution also isn't perfect, because of how blazor server works they will remain authenticated as long as the circuit stays alive regardless of when the cookie expires
I got it
The ideal solution is to use a revalidatingserverauthenticationstateprovider
I can't do that, man. I'm sorry! I probably gonna be fired if i post the code here.
Unknown User•4w ago
Message Not Public
Sign In & Join Server To View
I think i saw something like that on documentation. I'm going to look and try to use
Code isn't really needed here tebe
The issue is you can't set cookies through a blazor server circuit
Unknown User•4w ago
Message Not Public
Sign In & Join Server To View