Blazor Wasm Authentication (MSAL): Not waiting for token

Moinuddin 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

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,396 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,560 questions
0 comments No comments
{count} votes

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

    Hi @Moinuddin 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 @Moinuddin 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