首页 > 解决方案 > 客户端和用户使用 Identity Server 访问受保护的 API

问题描述

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

场景比较简单:

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

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

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

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

标签: asp.net-coreidentityserver4asp.net-core-webapiopenid-connect

解决方案


是的,如果您希望仅将 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)。


推荐阅读