问题
I am trying to implement a basic custom Auth provider in my server side blazor project, but I am having some difficulty implementing the 'IsAuthenticating' property correctly.
I used this site as my starter point, but it throws an error if 'IsAuthenticating
' is set to true (more specifically when I return null from GetAuthenticationStateAsync()
). https://gunnarpeipman.com/client-side-blazor-authorizeview/.
Specifically this line of code:
if(IsAuthenticating)
{
return null; <---- This line throws error
}
else if(IsAuthenticated)
{
identity = new ClaimsIdentity(new List<Claim>
{
new Claim(ClaimTypes.Name, "TestUser")
}, "WebApiAuth");
}
else
{
identity = new ClaimsIdentity();
}
The exact error thrown is:
NullReferenceException: Object reference not set to an instance of an object.
Microsoft.AspNetCore.Components.Authorization.AuthorizeViewCore.OnParametersSetAsync()
I did not want to clutter with stack trace.
Can this be achieved, and if so how?
来源:https://stackoverflow.com/questions/60624778/how-to-implement-server-side-blazor-custom-authorization-provider-correctly