I get “Authorization has been denied for this request.” error message when using OWIN oAuth middleware (with separate Auth and Resource Server)

后端 未结 8 889
孤街浪徒
孤街浪徒 2020-12-15 04:35

I am attempting to decouple my auth and resource server. I am following the example provided in this tutorial:

http://bitoftech.net/2014/09/24/decouple-owin-authoriz

8条回答
  •  囚心锁ツ
    2020-12-15 05:17

    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);
    

提交回复
热议问题