✅ 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
Suiram1
Suiram14w ago
Do you force a reload of the browser the page after cookie was set?
Jimmacle
Jimmacle4w ago
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
Igor Bomfim
Igor BomfimOP4w ago
Yes, but it still not work. That looks interesting. Can you tell me more about it?
Jimmacle
Jimmacle4w ago
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
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Jimmacle
Jimmacle4w ago
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
Igor Bomfim
Igor BomfimOP4w ago
I got it
Jimmacle
Jimmacle4w ago
The ideal solution is to use a revalidatingserverauthenticationstateprovider
Igor Bomfim
Igor BomfimOP4w ago
I can't do that, man. I'm sorry! I probably gonna be fired if i post the code here.
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View
Igor Bomfim
Igor BomfimOP4w ago
I think i saw something like that on documentation. I'm going to look and try to use
Jimmacle
Jimmacle4w ago
Code isn't really needed here tebe The issue is you can't set cookies through a blazor server circuit
Unknown User
Unknown User4w ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?