【发布时间】:2021-02-01 16:53:38
【问题描述】:
我在 .NET5 中构建了我的第一个 Blazor WASM(客户端和服务器)应用程序,但在身份验证方面遇到了问题。 我的目标是不使用 Identity,因为我不想使用 localstorage 并且只有 JWT(或类似的)cookie 身份验证,如下图所示:Chrome DevTools。
我尝试过使用
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie( ... )
在服务器端,但我收到一个错误提示
There is no registered service of type 'Microsoft.AspNetCore.Components.Authorization.AuthenticationStateProvider'..
我没有错误
builder.Services.AddOidcAuthentication
在客户端的 Program.cs 中,但在我登录后应用程序未授权我(我的 cookie 中有一个令牌)。
我觉得我已经尝试了所有 Microsoft Docs 和教程,但没有运气,所以如果有人对此有解决方案,我将不胜感激!
【问题讨论】:
标签: c# blazor blazor-webassembly .net-5 asp.net-blazor