title: How to request cross domain with Aurelia using http-client
body: <p>I have a simple Data Resource that retrieves a flat json file from within my own project. When I try to replace the <code>url</code> with that of a Working API end point that I have running on a separate domain I get a 401 (Unauthorized) error in chrome.</p>
  
  <p><strong>SETUP:</strong> I have a Visual Studio solution with two projects.</p>
  
  <p>1) <strong>RateAppAPI</strong> (WebAPI Project w/ <a href="https://www.nuget.org/packages/Microsoft.AspNet.Cors/" rel="nofollow noreferrer">AspNet.cors</a>)<br>
  2) <strong>RateAppClient</strong> (ASPNET 5 Template w/ <a href="http://aurelia.io/docs.html#/aurelia/framework/latest/doc/article/what-is-aurelia" rel="nofollow noreferrer">Aurelia</a>)<br>
  3) I have both a <strong>flat file</strong> and an <strong>API endpoint</strong> serving up the same json document. You will see one commented in the code and the other un-commented.</p>
  
  <ol>
  <li>The API project is serving my GetAll route with no problems, I can
  hit the endpoint using postman and I get back a large result of
  Json. I have CORS enabled and setup properly, I have ruled that out
  as an issue.</li>
  <li>I have the client project running Aurelia in the wwwroot directory
  and I am using <a href="https://github.com/aurelia/fetch-client/blob/master/doc/article/en-US/http-services.md#aurelia-http-client" rel="nofollow noreferrer">aurelia-http-client</a> which I will provide the code
  for, but I will tell you that the example I will provide works with
  no problems using the flat file that I have in a directory within
  the client project.</li>
  <li>As long as I point the Get() request at the flat file within my own project  (of course) I have no issues pulling in the data and working with it. It is only when I switch the url to point at the endpoint that is on a different domain that I get a 401 (Unauthorized) error.</li>
  </ol>
  
  <p>Here is my code (an ES6 <a href="http://aurelia.io/docs.html#/aurelia/framework/latest/doc/article/what-is-aurelia" rel="nofollow noreferrer">Aurelia</a> module) that is the Data Resource:</p>
  
  <pre><code>import {inject} from "aurelia-framework";
  import {HttpClient} from "aurelia-http-client";
  
  let baseURL = "http://localhost/RateAppAPI/api/UtilZip/ByUtil/7";
  //let baseURL = "../api/utilzip/utilzip.json";
  
  @inject(HttpClient)
  
  export class UtilZipData {
  
  constructor(httpClient) {
      this.http = httpClient;
      this.http.configure(x =&gt; { x.withCredentials(); });
  }
  
  getAll() {
      return this.http.get(baseURL)
          .then(response =&gt; {
              return response.content;
          });
      }
  }
  </code></pre>
  
  <p>At the end of the day, I need to figure out how to use only Windows Auth and be able to run a client application from one domain, lets call that domain <code>localhost:1234</code> and access a different domain, lets call the API domain <code>localhost/RatAppAPI</code> The API will have CORS enabled using the following method:</p>
  
  <pre><code>public static void Register(HttpConfiguration config)
  {
      var cors = new EnableCorsAttribute("http://localhost:1234/", "*", "*");
      config.EnableCors(cors);
      config.MapHttpAttributeRoutes();
  
      config.Routes.MapHttpRoute(
          name: "DefaultApi",
          routeTemplate: "api/{controller}/{id}",
          defaults: new { id = RouteParameter.Optional }
      );
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/kCVeN.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kCVeN.jpg" alt="enter image description here"></a></p>