我创建了一个自定义ApiAuthenticationStateProvider
返回后AuthenticationState
仍在说明
info: Microsoft.AspNetCore.Authorization.DefaultAuthorizationService[2]
Authorization failed.
这是我的简化版本ApiAuthenticationStateProvider
那是失败的:
public class ApiAuthenticationStateProvider : AuthenticationStateProvider
{
public override Task<AuthenticationState> GetAuthenticationStateAsync()
{
Console.WriteLine("Getting auth state...");
var claims = new[] { new Claim(ClaimTypes.Name, "[email protected] /cdn-cgi/l/email-protection") };
var authenticatedUser = new ClaimsPrincipal(new ClaimsIdentity(claims));
var authState = Task.FromResult(new AuthenticationState(authenticatedUser));
return Task.FromResult(authState);
}
}
我可以从Console.WriteLine
这是使用我的自定义提供程序,但为了提供完整的详细信息,这是我用来添加该内容的代码Program.cs
:
builder.Services.AddScoped<AuthenticationStateProvider, ApiAuthenticationStateProvider>();
这个问题可以在这个答案中得到解决。https://stackoverflow.com/a/20254797/2682662 https://stackoverflow.com/a/20254797/2682662
基本上在构建时ClaimsIdentity
您需要为身份验证类型提供一个字符串值。
var authenticatedUser = new ClaimsPrincipal(new ClaimsIdentity(claims, "Needs Auth Type Here"));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)