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, "some.email@somewhere.com") };
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>();