identityserver4 - 使用多个 IDServer 保护单个 api 资源
问题描述
所以我有一个 .Net Core web api,我们称它为“CMS”,它目前由 IdentityServer4 服务器作为 api 资源保护。我已将 ID4 服务器配置为具有 MyIDP 的 IDP 声明。
出于商业原因,我需要为客户提供他们自己的 IdentityServer,但他们也希望让他们的用户访问相同的 api "CMS" 。
这可能吗?在我的 CMS api 的 StartUp.cs 中,它目前看起来像这样
services.AddAuthentication("Bearer")
.AddIdentityServerAuthentication(options =>
{
options.Authority = "http://www.idserver1.com";
options.RequireHttpsMetadata = true;
options.ApiName = "cmsapi";
});
因此,为了增加对另一个 id 服务器的保护,我假设我可以复制AddAuthentication
但将方案名称从 Bearer 更改为其他名称,但这似乎是错误的?
我认为这应该是可能的原因是我已经能够以这种方式将多个外部提供程序添加到我的 Web 应用程序中。但这是针对 s 登录流程,而不是针对 api。
如果这是可能的,我该怎么做?
解决方案
这可以很简单地实现。假设您想为每个客户颁发一个单独的子域:auth0.yourdomain.com
,auth1.yourdomain.com
并且您希望 api 资源尊重来自这些身份提供者中的任何一个的令牌。
假设签名密钥相同,您可以在身份服务器端配置共享颁发者 uri Startup.cs->ConfigureServices(...)
:
var builder = services.AddIdentityServer(options => {
options.IssuerUri = "auth.yourdomain.com";
})
...
然后在 api 方面,您可以尊重单个颁发者 uri,而无需复制身份验证方案:
services.AddAuthentication("Bearer")
.AddIdentityServerAuthentication(options =>
{
options.Authority = "auth.yourdomain.com";
options.RequireHttpsMetadata = true;
options.ApiName = "cmsapi";
});
我不记得的一件事是是否为颁发者 uri 推断了请求方案 (http/https),因此您可能还需要指定它 ( https:\\auth.yourdomain.com
)。除此之外,就您的客户而言,这种实现应该是非常无缝的。
推荐阅读
- metabase - 有没有办法从 Metabase 连接到 sanity.io 数据库/数据存储数据?
- postgresql - Azure 托管 PostgreSQL 服务上的中断 VACUUM FULL 消耗了大量空间。我该如何恢复它?
- javascript - Jquery在滚动上添加和删除类
- laravel-8 - 无法在 Laravel 8 中安装 Bootstrap 5.0.1 包
- kubernetes - 使用 CSI 机密驱动程序提供的保险库机密作为 Kubernetes 中的环境变量
- python - O365 API,转发电子邮件
- here-api - HERE 地理编码在多词搜索词上返回空响应
- google-apps-script - 如何根据您在谷歌表格中的标准操作数据?
- rust - 避免结构生锈中的生命周期参数?
- javascript - 文件上传暂停,显示模态窗口,继续上传