title: Graph API with ASP.NET Core Blazor WebAssembly
body: <p>I would like to get information from Microsoft graph web API. I followed these instructions:</p>
  <p><a href="https://docs.microsoft.com/en-us/aspnet/core/blazor/security/webassembly/graph-api?view=aspnetcore-5.0" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/aspnet/core/blazor/security/webassembly/graph-api?view=aspnetcore-5.0</a></p>
  <p>The problem is that the variable &quot;token&quot; in the AuthenticateRequestAsync method is always null. It means that the Blazor app does not get the token.</p>
  <pre><code>public async Task AuthenticateRequestAsync(HttpRequestMessage request)
              {
                  var result = await TokenProvider.RequestAccessToken(
                      new AccessTokenRequestOptions()
                      {
                          Scopes = new[] { &quot;https://graph.microsoft.com/User.Read&quot; }
                      });
      
                  if (result.TryGetToken(out var token))
                  {
                      request.Headers.Authorization ??= new AuthenticationHeaderValue(
                          &quot;Bearer&quot;, token.Value);
                  }
              }
  </code></pre>
  <p>The Program.cs has the following code:</p>
  <pre><code>builder.Services.AddScoped(sp =&gt; new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
  
              builder.Services.AddMsalAuthentication&lt;RemoteAuthenticationState, RemoteUserAccount&gt;(options =&gt;
               {
                   options.ProviderOptions.DefaultAccessTokenScopes.Add(&quot;https://graph.microsoft.com/User.Read&quot;);
                   builder.Configuration.Bind(&quot;AzureAd&quot;, options.ProviderOptions.Authentication);
                   
               });
  
              builder.Services.AddGraphClient(&quot;https://graph.microsoft.com/User.Read&quot;);
  </code></pre>
  <p>In Index.razor I just add two lines of code I OnInitializedAsync method</p>
  <pre><code>var request = GraphClient.Me.Request();
  user = await request.GetAsync();
  </code></pre>
  <p>I spent a lot of time to figure out what is the main issue but without success. I will appreciate any help.</p>