Authorization has been denied for this request - New Web API Project

前端 未结 4 713
渐次进展
渐次进展 2021-01-30 10:58

I just created new Web API project (using MVC) in visual studio 2015 and for the testing purpose, I ran that project but ended up below error.

After running the project,

4条回答
  •  无人共我
    2021-01-30 11:34

    I got the answer here.

    https://stackoverflow.com/a/29405794/8107314

    And it was very useful to fix my error my error

    I just came across the same problem and found the solution:

    You need to register the OAuth Token Generator and OAuth Token Consumer things before WebAPI is registered.

    Kind of makes sense if you think of this as a pipeline, where Authentication/Authorization should come before any request handling by the controllers.

    TL;DR: Change

    appBuilder.UseWebApi(config);
    
    this.ConfigureOAuthTokenGenerator(appBuilder);
    this.ConfigureOAuthConsumer(appBuilder);
    

    To

    this.ConfigureOAuthTokenGenerator(appBuilder);
    this.ConfigureOAuthConsumer(appBuilder);
    
    appBuilder.UseWebApi(config);
    

提交回复
热议问题