I want to host my API on a separate domain. I have configured my auth-interceptor for token in angular with a bearer:
config.headers.Authorization = 'Bearer ' + sessionStorage.getItem('token');
In my My WebApi2 I have configured the WebApiConfig with cors.
var cors = new EnableCorsAttribute("http://mydomain.com", "*", "*");
config.EnableCors(cors);
And in web.config of the API I also included:
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
I still can´t access the api due to origin not allowed. Can I add something more in my header of the auth-interceptor in angular or what do I need to do?
In web.config of API, include the below mentioned code:
I hope this helps.
Thanks.
I've had the same issue before and what worked for me was to remove the settings from the web.config and just leave the configuration settings in the
WebApiConfig
classSee this answer for more details
your Angular.js interceptor settings are ok. I've got a public project with your same scenario, with OAuth+Owin authentication. The steps I followed are:
Hope this helps