title: Azure AD Access Token Request
body: <p>In my WebAssembly Blazor App, I need to access an API that I'm developing and Microsoft.Graph.</p>
  
  <p>As I understood, I cannot use the same bearer token for 2 different resources (my API and Graph).</p>
  
  <p>I setup the access to my API with MSAL in Program.cs</p>
  
  <pre class="lang-cs prettyprint-override"><code>builder.Services.AddBaseAddressHttpClient();
  builder.Services.AddMsalAuthentication(options =&gt;
  {
      var authentication = options.ProviderOptions.Authentication;
      authentication.Authority = "https://login.microsoftonline.com/xxx";
      authentication.ClientId = "xxx";
      options.ProviderOptions.DefaultAccessTokenScopes.Add("xxx/user_impersonation");
  });
  </code></pre>
  
  <p>And I'm trying to get the token for the Graph API directly when I need it (following <a href="https://docs.microsoft.com/en-us/graph/auth-v2-service?view=graph-rest-1.0" rel="nofollow noreferrer">this</a>):</p>
  
  <pre class="lang-cs prettyprint-override"><code>internal class Token
  {
      [JsonProperty("access_token")]
      public string AccessToken { get; set; }
  
      [JsonProperty("token_type")]
      public string TokenType { get; set; }
  
      [JsonProperty("expires_in")]
      public int ExpiresIn { get; set; }
  
      [JsonProperty("refresh_token")]
      public string RefreshToken { get; set; }
  }
  
  private static async Task&lt;Token&gt; GetElibilityToken(HttpClient client)
  {
      string baseAddress = @"https://login.microsoftonline.com/xxx/oauth2/v2.0/token";
  
      string grant_type = "authorization_code";
      string client_id = "xxx";
      string client_secret = "==xxx";
      string scope = "https://graph.microsoft.com/.default";
  
      var form = new Dictionary&lt;string, string&gt;
          {
              {"grant_type", grant_type},
              {"client_id", client_id},
              {"client_secret", client_secret},
              {"scope", scope }
          };
  
      HttpResponseMessage tokenResponse = await client.PostAsync(baseAddress, new FormUrlEncodedContent(form));
      var jsonContent = await tokenResponse.Content.ReadAsStringAsync();
      Token tok = JsonConvert.DeserializeObject&lt;Token&gt;(jsonContent);
      return tok;
  }
  </code></pre>
  
  <p>Is the approach correct? Is there a better one?</p>
  
  <p>Should I register 2 <code>IAccessTokenProvider</code> in Program.cs? How?</p>
  
  <p>The problem I have is that I keep getting the error:</p>
  
  <pre><code>Access to fetch at 'https://login.microsoftonline.com/xxx/oauth2/v2.0/token' from origin 'https://localhost:xxx' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
  dotnet.3.2.0-preview2.20159.2.js:1 POST https://login.microsoftonline.com/xxx/oauth2/v2.0/token net::ERR_FAILED
  </code></pre>
  
  <p>How do I setup CORS in my request?</p>