【问题标题】:Client and User Access to protected API using Identity Server客户端和用户使用 Identity Server 访问受保护的 API
【发布时间】:2019-08-16 23:10:01
【问题描述】:

我想知道我希望在我的项目中使用的 Identity Server 的一个方面。

场景比较简单:

  • 我有一个 API 和几个客户端
  • 我想使用 Identity Server 和 OIDC 保护该 API
  • 在一个客户端上,我正在研究具有可选身份验证的概念。
    • 某些功能需要某些声明,即管理员
    • Rest 应该允许匿名用户访问,但应该只允许来自注册客户的请求
    • 这也应该反映在 API 上

这里需要注意的是,我仍然希望将 API 限制为仅由 Identity Server 中的注册客户端访问

Identity Server 中是否可能出现这种情况?

我知道我会在 API 上设置管理策略,但我是否还必须设置 CORS 功能,或者 Identity Server 是否使用允许的范围和资源配置直接执行此操作?

抱歉,如果解释不佳,我会尽快添加图表

【问题讨论】:

    标签: asp.net-core identityserver4 asp.net-core-webapi openid-connect


    【解决方案1】:

    是的,如果您希望仅对经过身份验证的请求限制 API 访问,一种方法是通过设置全局授权策略来进行范围验证(请参阅https://github.com/IdentityServer/IdentityServer4.AccessTokenValidation)。

    您的管理员端点将检查其他声明。有几种方法可以做到这一点,一种方法是基于策略的授权 (https://docs.microsoft.com/en-us/aspnet/core/security/authorization/policies?view=aspnetcore-2.2)。

    您需要为您的 API 配置 CORS 中间件(请参阅https://docs.microsoft.com/en-us/aspnet/core/security/cors?view=aspnetcore-2.2)。如果您需要 COR 访问 Identity Server 端点,则需要配置 Identity Server(请参阅 http://docs.identityserver.io/en/latest/topics/cors.html)。

    【讨论】:

    • 感谢@devdigital
    猜你喜欢
    • 2017-02-08
    • 2018-05-03
    • 2015-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-23
    • 1970-01-01
    • 2019-05-11
    相关资源
    最近更新 更多