混合IdentiyServer4和WebAPI .net 4.5.2

时间:2018-08-25 08:44:24

标签: asp.net-web-api identityserver4 identityserver3

我是IdentityServer的新手。我已遵循IdentityServer4教程here

但是本教程仅显示如何保护.net核心API。我找不到使用IdentityServer4的任何教程,该教程还显示了如何保护.net 4.#WebAPI。我在StackOverflow here上找到了一篇建议使用Microsoft Katana JWT中间件的帖子,但是我不知道如何实现,因为我对此并不陌生。

任何人都可以向我指出一个教程(或根据需要进行组合),它将为我指明正确的方向。预先感谢。

更新:

我正在尝试将IdentityServer3用于API,将IdentityServer4用于授权服务器。

我已经创建了一个IdentityServer4授权服务器,看来工作正常。

我创建了一个WebAPI(使用完整的.Net框架-在本例中为4.7.1)。我已遵循IdentityServer3文档中有关如何将IdentityServer合并到API中的说明。因此,正如预期的那样,当我尝试通过浏览器直接导航到控制器时,我得到了401 Unauthoriased Access,因此很安全。

我已经创建了一个控制台客户端。我已经将其配置为指向IdentityServer4 Auth Server,现在又获得了访问令牌。

直到现在,当我在客户端上使用带有此访问令牌的SetBearerToken时,我仍然会收到401未经授权。我已经将http和https都用作了授权服务器...我现在又挠头了!

1 个答案:

答案 0 :(得分:1)

Here是完整的示例。正如您在简要指南中所描述的那样, 您需要做的(添加所有必要的软件包之后)是将以下内容添加到Startup.cs中:

from keras.applications.imagenet_utils import decode_predictions

事实证明,当与catch (IOException e) { return e.getMessage(); } 选项一起使用时,Identityserver 3中的app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions { Authority = "https://identity.identityserver.io", RequiredScopes = new[] { "api1", "api2" } }); 与Identityserver 4不兼容。切换到ValidationMode.Local可以解决这种情况。