Search code examples
azureblazorazure-ad-b2cwebassembly

Blazor Azure AD B2C net 5 Error trying to login


I'm following the instructions for setting up a Blazor Web Assembly hosted using Azure AD B2C located here: https://learn.microsoft.com/en-us/aspnet/core/blazor/security/webassembly/hosted-with-azure-active-directory-b2c?view=aspnetcore-5.0

When the login is clicked a message appears stating 'There was an error trying to log you in: 'Error: could not resolve endpoints. Please check network and try again. Detail: TypeError: NetworkError when attempting to fetch resource.'

In the debug window the message is displayed: Microsoft .AspNetCore.Authorization.DefaultAuthorizationService[2] Authorization failed. These requirements were not met: DenyAnonymousAuthorizationRequirement: Requires an authenticated user.

In the Microsoft instructions for this error message the recommendation is in Azure for the app set the manifest setting of allowPublicClient to null or true. I set this attribute for both the server app and the client app to true but this did not make a difference.


Solution

  • I was able to follow the instructions in your link and make it work.

    Some things to try for the client app registration:

    • 'Authentication': For the 'Platform configurations' make sure you choose SPA and the redirect urls are correct
    • 'Authentication': For 'Implicit grant' don't check 'Access tokens' and 'ID tokens'
    • 'API permissions' make sure you added the server registration and clicked 'Grant admin consent'