Angular5 WebApi token authorization not working

前端 未结 1 1245
遇见更好的自我
遇见更好的自我 2020-12-22 05:15

I\'m trying to implement token authorization for Angular5 client and WebApi server application. I have managed to create WebApi part of the project in question and when I tr

相关标签:
1条回答
  • 2020-12-22 06:10

    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.

    0 讨论(0)
提交回复
热议问题