Blazor Wasm Authentication (MSAL): Not waiting for token

Moin Mohamed 46 Reputation points
2022-01-28T14:14:03.843+00:00

Hi,

I have a standalone Blazor Webassembly app (.NET 6) with authentication implemented with Azure AD, using MSAL.

In Program.cs, I am using the following auth configuration:

builder.Services.AddMsalAuthentication(options =>  
{  
    var scopes = builder.Configuration.GetValue<string>("AzureAd:Scopes");  
  
    options.ProviderOptions.DefaultAccessTokenScopes.Add(scopes);  
  
    builder.Configuration.Bind("AzureAd", options.ProviderOptions.Authentication);  
});  

For the rest of the app's auth configuration, I have the same setup as described in standalone-with-azure-active-directory.

The issue is that, when logging in using the "redirect" login mode, even after successfully logging in, when the user is redirected back to the app from Microsoft's login page, the app thinks the user is still unauthenticated. If the user then subsequently hits refresh, the app successfully logs the user in.

Any help with this issue would be much appreciated as I've been dealing with it for a while now.

Thanks

Azure Active Directory
Azure Active Directory
An Azure enterprise identity service that provides single sign-on and multi-factor authentication.
13,570 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.
882 questions
No comments
{count} votes

Accepted answer
  1. Shweta Mathur 13,076 Reputation points Microsoft Employee
    2022-02-01T11:07:56.3+00:00

    Hi @Moin Mohamed ,

    Thanks for reaching out.

    I have tried the sample application mentioned in the document and added "redirect" login in program.cs as below. I am successfully able to redirect to application after login using "redirect" in same way as popup.

    builder.Services.AddMsalAuthentication(options =>  
    {  
        ...  
        options.ProviderOptions.LoginMode = "redirect";  
    });  
    

    As mentioned by @Moin Mohamed , the issue here is due to redirect URL has not been configured properly while registering the application due to which user is not able to access that URL.

    Thanks,
    Shweta


0 additional answers

Sort by: Most helpful