0

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?

0m3r
  • 12,286
  • 15
  • 35
  • 71
John Dover
  • 739
  • 1
  • 8
  • 19
  • The latest preview (3.2.0 Preview 2) supports this 'out of the box'. Review that first. https://devblogs.microsoft.com/aspnet/blazor-webassembly-3-2-0-preview-2-release-now-available/ – H H Mar 11 '20 at 19:04
  • Thanks for the link I will review. – John Dover Mar 11 '20 at 19:11
  • I missed that 'server-side'. That makes your question an odd one, but not impossible. Do note that the template solution relies on the ASP.NET cookie, you'll have to think about using or replacing that. – H H Mar 11 '20 at 21:04
  • I have been reviewing the link you provided, and even installed the template you suggested. Still processing all the information and trying to find a way to utilize the webassembly blazor as I need. I have a unique requirement to utilize jwt tokens with windows authentication. IE. My api endpoint to retrieve token is windows auth, but returns a token to be used in client applications that may be on the public network or private network. I appreciate the simple link. I believe I have been incorrect to utilize server side blazor for client application. – John Dover Mar 11 '20 at 21:21

0 Answers0