简体   繁体   中英

Blazor - Server Side - Cookie Authentication

I want to implement the Authentication in Blazor Server Side, using the cookie Authentication, I have checked a lot of sample projects, but all of them are using Microsoft.Identity.

The problem with cookie auth and server-side Blazor, is that the web socket that server-side Blazor uses to talk to the server will remain open and connected long after the cookie expires. There might be a way to end/refresh this websocket periodically, but I didn't look into it.

If your actually using Blazor WebAssembly you have to implement your own AuthenticationStateProvider that manages your login/logout.

You'll also want to implement a /user/keepalive endpoint so that when a user navigates their cookie is kept alive. See Blazor's NavigationManager.LocationChanged

As well as a /user/me endpoint to detect if the cookie is still valid, and load any permissions when a user hits F5. Nothing more annoying than logging in, hitting F5 and having to login again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM