Unable to add parameters to login request using Blazor `<RemoteAuthenticatorView>` component

I have Blazor WebAssembly application and I use Auth0 for authentication. Getting it to work was a dream, compared to using Microsofts’ offerings. However, now I am running into a roadblock. I use the <RemoteAuthenticatorView> component to handle initiating the login request. In .NET 7, you can customize these requests by adding an InteractiveRequestOptions object to the NavigateToLogin() overload of NavigationManager:

    void BeginLogin(string connectionName)
    {
        var requestOptions = new InteractiveRequestOptions()
        {
            Interaction = InteractionType.SignIn,
            ReturnUrl = NavigationManager.BaseUri
        };
        if (!requestOptions.TryAddAdditionalParameter("connection", connectionName))
        {
            throw new InvalidOperationException("Unable to add parameter");
        }
        NavigationManager.NavigateToLogin("authentication/login", requestOptions);
    }

In this case, I want to add a connection=xxx url parameter to the /authorize endpoint to select a specific connection. Unfortunately, the parameter is not added to the url generated by the <RemoteAuthenticatorView> component. Is there anything I need to configure in the application? Do I need to whitelist these parameters in some way? Any help would be greatly appreciated!

Solved it! After a lot of trial and error, I managed to get it to work. The trick is to wrap the parameters in a dictionary and supply these to the extraQueryParams parameter (note the abbreviated params). The following code works:

 void BeginLogin(string connectionName)
    {
        var requestOptions = new InteractiveRequestOptions()
        {
            Interaction = InteractionType.SignIn,
            ReturnUrl = NavigationManager.BaseUri
        };

        if (!requestOptions.TryAddAdditionalParameter("extraQueryParams", new Dictionary<string, string>()
        {
            {"connection", connectionName }
        }))
        {
            throw new InvalidOperationException("Unable to add parameter");
        }
        NavigationManager.NavigateToLogin("authentication/login", requestOptions);
    }
3 Likes

Hey there @bram.fokke welcome to the community, and thanks for following up with your solution! :rocket:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.