title: Getting a XMLHttpRequest: Network Error 0x80070005, Access is denied
body: <p>I have a token endpoint that is passed a username and password grant type to authenticate users. This token endpoint is called from an AngularJS service that is part of my MVC web front end. When I call the service I get the following error</p>
  
  <pre><code>XMLHttpRequest: Network Error 0x80070005, Access is denied.
  </code></pre>
  
  <p>This seems to be a CORS problem. I did the following to resolve this problem with no luck thus far</p>
  
  <p>I added the <code>app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);</code> to my <code>Startup.cs</code> file for my token web service.</p>
  
  <pre><code>public class Startup
  {
      public void Configuration
      (
      IAppBuilder app
      )
  {
      ConfigureOAuth(app);
  
      var config = new HttpConfiguration();
      WebApiConfig.Register(config);
  
      config.Filters.Add(new AuthorizeAttribute());
  
      app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
  
      app.UseWebApi(config);
  }
  
  private void ConfigureOAuth
      (
      IAppBuilder app
      )
  {
     app.UseOAuthAuthorizationServer(new OAuthServerOptionsProvider().Provide());
     app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
  }
  </code></pre>
  
  <p>I also have a class that is overriding the <code>OAuthAuthorizationServerProvider</code>, within the <code>GrantResourceOwnerCredentials</code> method I have the following code to add all origins to the response headers</p>
  
  <pre><code> public override async Task GrantResourceOwnerCredentials
       (
       OAuthGrantResourceOwnerCredentialsContext context
       )
   {
       System.Web.HttpContext.Current.Response.Headers.Add("Access-Control-Allow-Origin", "*");
      // Other code left out to keep this short
   }
  </code></pre>
  
  <p>In fiddler I can see that the response header was successfully added</p>
  
  <p><a href="https://i.stack.imgur.com/5k4Tt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5k4Tt.png" alt="enter image description here"></a></p>
  
  <p>Is there something I'm missing here?</p>
  
  <p><strong><em>Update</em></strong></p>
  
  <p>Here is my request headers</p>
  
  <p><a href="https://i.stack.imgur.com/Hl5qx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Hl5qx.png" alt="enter image description here"></a></p>