How to stay logged in during development of a Blazor Web Assembly app that uses Azure AD B2C for authentication

Viewed 260

I am developing a Blazor Web Assembly app in Visual Studio that uses Azure AD B2C for authentication. It is all setup and working well except that developing is a chore because each time I want to launch the debugger and open the browser to review my work I am required to login in again to view pages that require authentication. This is a time consuming and annoying step that I would hope to avoid.

Ideally there would be a way to stay logged in between debug browser sessions launched from Visual Studio.

I have searched for the answer on the web with not luck yet. Anyone have any ideas on how to do this?

2 Answers

In Program.cs, set MsalCacheOptions.CacheLocation to "localStorage"

Example:

    builder.Services.AddMsalAuthentication(options =>
    {
        // Keeps logged in between debugging sessions
        options.ProviderOptions.Cache.CacheLocation = "localStorage";

        // Set up other options
        ...
    });

One work around I have found is to open a second browser window to the local debugging endpoint (https://localhost:5001/ in my case). When I login to the app in this browser and then refresh the browser I will stay logged in.

So, as I work, when I am ready to review something, I launch the debugger in Visual Studio which opens a new browser window, but then I ignore that window and refresh the first window I already had open in which I was already logged in and review my work there. It is a couple extra clicks but I don't need to login again.

Related