Blazor WebAssembly Hosted app using Azure AD B2C - How to determine when the user clicked Cancel?

sdobbi 6 Reputation points
2022-09-19T20:48:23.73+00:00

I have a Blazor WebAssembly Hosted C# application (.NET 6.0) using Azure AD B2C. On the B2C login screen, if the user clicks Cancel for Forgot Password, Sign-Up or Create Account, B2C will redirect to /authentication/login-callback within the Blazor app. How can I determine whether the user clicked Cancel in B2C within Authentication.razor in the Blazor app? There are no query string values when /authentication/login-callback enters Authentication.razor. Also, /authentication/login-callback changes to /authentication/login-failed?message=AADB2C90091 in the browser but does not enter the OnInitializedAsync method in Authentication.razor.

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,386 questions
Microsoft Entra External ID
Microsoft Entra External ID
A modern identity solution for securing access to customer, citizen and partner-facing apps and services. It is the converged platform of Azure AD External Identities B2B and B2C. Replaces Azure Active Directory External Identities.
2,639 questions
{count} votes

1 answer

Sort by: Most helpful
  1. sdobbi 6 Reputation points
    2022-09-30T23:13:21.507+00:00

    The problem was solved by adding a Razor component and adding the component to the LogInFailed section of the Authentication.razor file. The LoginFailedRedirect.razor file redirects the user back to the Azure AD B2C login screen. Please see the details below.

    Authentication.razor excerpt:
    @Anonymous "/authentication/{action}"
    @using Microsoft.AspNetCore.Components.WebAssembly.Authentication

    <RemoteAuthenticatorView Action="@朱大星 " OnLogOutSucceeded=@this.OnLogOutSucceeded OnLogInSucceeded=@this.OnLogInSucceeded >
    <LoggingIn>
    <div>LoggingIn</div>
    </LoggingIn>
    <LogInFailed>
    <LoginFailedRedirect />
    </LogInFailed>

    <LogOut>
    <div>LogOut</div>
    </LogOut>
    </RemoteAuthenticatorView>

    LoginFailedRedirect.razor:
    @inject NavigationManager Navigation

    @Aidan Wick {
    protected override void OnInitialized()
    {
    Navigation.NavigateTo($"authentication/login");
    }
    }

    A specific error code can be obtained from the message query string value in the LoginFailedRedirect.razor. Below is an example of the excerpt of the return URL from Azure AD B2C.
    /authentication/login-failed?message=AADB2C90091%3A%20The%20user%20has%20cancelled%20entering%20self-asserted%20information.

    0 comments No comments