Angular5 WebApi token authorization not working

烂漫一生 提交于 2019-11-29 16:33:13

Thanks David for your help. I tried your solution but it didn't help until I changed my WebAPI CORS settings. The issue was with Pre-flight CORS request. I followed instructions in this article and that solved my issue.

In short:

  1. I cleared all settings regarding CORS on my WebAPI and installed Microsoft.Owin.Cors package.
  2. Then I modified the ConfigureAuth method in the App_Start\Startup.Auth.cs file with the following code:

    public void ConfigureAuth(IAppBuilder app) { app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
    app.UseOAuthBearerTokens(OAuthOptions); }

That solved the issue, even with my code in Angular from the question. It now works fine.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!