Bypass the "Pick user popup" after Sign out in a .Net 8 Blazor WASM application

Scot Woodyard 20 Reputation points
2024-02-16T19:04:01.1266667+00:00

Is it possible to bypass the "Pick user popup" after Sign out with Azure/Entra ID? We need to execute an automatic sign out when the user is not active. The application is a Blazor WASM application. Here is my Program.cs code:

using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using THDVirtualAgent;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");

builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

builder.Services.AddMsalAuthentication(options =>
{
    builder.Configuration.Bind("AzureAd", options.ProviderOptions.Authentication);
    // Redirect to home page after login failure
    options.AuthenticationPaths.LogInFailedPath = "/?loginFailed=true"; 
    // Redirect to home page after logout
    options.AuthenticationPaths.LogOutSucceededPath = "/";
});

var assemblyName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;

await builder.Build().RunAsync();

Here is the code I am currently using to log the user out:

        /// <summary>
        /// Handles user inactivity.
        /// This method is invoked from JavaScript when the user has been inactive for a certain period of time.
        /// It sets the sign out state and navigates to the logout page.
        /// </summary>
        /// <returns>A completed Task.</returns>
        [JSInvokable]
        public Task HandleInactivityAsync()
        {
            //Set the sign out state using the SignOutSessionStateManager
            SignOutManager.SetSignOutState();

            // Currently not used, but could be used to extract the login hint from the user's claims
            var loginHint = ExtractLoginHintFromClaims();
            
            //Navigate to the logout page
            NavigationManager.NavigateTo($"authentication/logout");
        
            return Task.CompletedTask;
        }

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,862 questions
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,580 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Marilee Turscak-MSFT 36,846 Reputation points Microsoft Employee
    2024-02-16T19:31:18.7866667+00:00

    @Scot Woodyard , If you want sign-out to occur without prompting the user to select an account, you can use the logout_hint claim:

    To use logout_hint, enable the login_hint optional claim in your client application and use the value of the login_hint optional claim as the logout_hint parameter. Don't use UPNs or phone numbers as the value of the logout_hint parameter.

    You should also be able to use the domain_hint claim.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.