MSAL error AADB2C90146

anastasia 21 Reputation points
2022-04-27T10:52:30.687+00:00

I have a hosted Blazor WebAssembly app secured with Azure AD B2C. I need to call GraphAPI from my app to get some custom user information. I used this article to set up the service, but it doesn't work. I get an error message when I try to access pages that need authentication or log in:

196919-image.png

The message is kind of self explaining, but I don't understand how shall I do it.

Here I set AddMsalAuthentication

builder.Services.AddMsalAuthentication(options =>  
{  
    builder.Configuration.Bind("AzureAdB2C", options.ProviderOptions.Authentication);  
    options.ProviderOptions.DefaultAccessTokenScopes.Add(  
        "https://xxx.onmicrosoft.com/xxxxxxx-a5f50ab3378d/API.Access");  
  
    options.ProviderOptions.LoginMode = "redirect";  
});  

and Microsoft Graph

builder.Services.AddGraphClient("https://graph.microsoft.com/User.Read");  
Microsoft Security | Microsoft Entra | Microsoft Entra External ID
Microsoft Security | Microsoft Entra | Microsoft Entra ID
Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

Answer accepted by question author
  1. CarlZhao-MSFT 46,406 Reputation points
    2022-04-28T03:08:26.07+00:00

    Hi @anastasia

    The error is a scope conflict, the https://xxx.onmicrosoft.com/xxxxxxx-a5f50ab3378d/API.Access is your custom web api not graph api. You cannot request tokens for two different types of api, please changed it to graph api.

     builder.Services.AddMsalAuthentication(options =>  
     {  
         builder.Configuration.Bind("AzureAdB2C", options.ProviderOptions.Authentication);  
         options.ProviderOptions.DefaultAccessTokenScopes.Add(  
             "https://graph.microsoft.com/User.Read");  
          
         options.ProviderOptions.LoginMode = "redirect";  
     });  
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

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