【问题标题】:IdentityServer4 Duplicate ScopesIdentityServer4 重复范围
【发布时间】:2018-05-19 03:54:47
【问题描述】:

我有一个 REST Web 服务,我们可以部署 n 个客户端。部署了相同的应用程序,只是配置不同。我们有一个与这些 REST Web 服务实例对话的 Web 前端网站。用户使用 IdentityServer4 对实例进行身份验证,使用前端调用后端 Web 服务实例,并将令牌传递给它。

我需要防止检索到的授予 webservice-X 访问权限的令牌用于访问 webservice-Y。理想情况下,我会为每个部署的具有相同范围的客户端定义一个 ApiResource。尝试进行身份验证时收到以下错误消息:

发现重复的 API 范围。这是一个无效的配置。对 API 范围使用不同的名称。找到的范围:PaymentApi、DocumentApi

有没有办法可以禁用此重复检查?是否有另一种方法来配置所有内容来完成此操作?

我的部分配置:

            new ApiResource
            {
                Name = "WebService-X",
                DisplayName = "WebService-X",
                Description = "Client Api residing on customer-X network",
                Enabled = true,
                Scopes = new List<Scope>()
                {
                    new Scope()
                    {
                        Name = "PaymentApi",
                        DisplayName = "PaymentApi",
                        ShowInDiscoveryDocument = true,
                    },
                    new Scope()
                    {
                        Name = "DocumentApi",
                        DisplayName = "DocumentApi",
                        ShowInDiscoveryDocument = true,
                    }
                },
                ApiSecrets = new List<Secret>
                {
                    new Secret("fdzxGSDFHY)GSFD*U)DIS:LGJSLKFDJGG".Sha256())
                },
            },
            new ApiResource
            {
                Name = "WebService-Y",
                DisplayName = "WebService-Y",
                Description = "Client Api residing on customer-Y network",
                Enabled = true,
                Scopes = new List<Scope>()
                {
                    new Scope()
                    {
                        Name = "PaymentApi",
                        DisplayName = "PaymentApi",
                        ShowInDiscoveryDocument = true,
                    },
                    new Scope()
                    {
                        Name = "DocumentApi",
                        DisplayName = "DocumentApi",
                        ShowInDiscoveryDocument = true,
                    }
                },
                ApiSecrets = new List<Secret>
                {
                    new Secret("fdzxGSDFHY)GSDFS$#%#$LKFDJGG".Sha256())
                },
            },

我想避免这样的事情,因为它不能很好地扩展:

                new ApiResource
                {
                    Name = "WebService-X",
                    DisplayName = "WebService-X",
                    Description = "Client Api residing on customer-X network",
                    Enabled = true,
                    Scopes = new List<Scope>()
                    {
                        new Scope()
                        {
                            Name = "PaymentApi-X",
                            DisplayName = "PaymentApi-X",
                            ShowInDiscoveryDocument = true,
                        },
                        new Scope()
                        {
                            Name = "DocumentApi-X",
                            DisplayName = "DocumentApi-X",
                            ShowInDiscoveryDocument = true,
                        }
                    },
                    ApiSecrets = new List<Secret>
                    {
                        new Secret("fdzxGSDFHY)GSFD*U)DIS:LGJSLKFDJGG".Sha256())
                    },
                },
                new ApiResource
                {
                    Name = "WebService-Y",
                    DisplayName = "WebService-Y",
                    Description = "Client Api residing on customer-Y network",
                    Enabled = true,
                    Scopes = new List<Scope>()
                    {
                        new Scope()
                        {
                            Name = "PaymentApi-Y",
                            DisplayName = "PaymentApi-Y",
                            ShowInDiscoveryDocument = true,
                        },
                        new Scope()
                        {
                            Name = "DocumentApi-Y",
                            DisplayName = "DocumentApi-Y",
                            ShowInDiscoveryDocument = true,
                        }
                    },
                    ApiSecrets = new List<Secret>
                    {
                        new Secret("fdzxGSDFHY)GSDFS$#%#$LKFDJGG".Sha256())
                    },
                },

【问题讨论】:

  • 范围必须有唯一的名称。

标签: asp.net-core identityserver4


【解决方案1】:

此验证是通过IResourceStoreExtensions 中的扩展方法完成的。无法覆盖此行为,因为intended design 是每个 API 资源的至少一个唯一 API 范围。

在您的特定情况下,您必须为每个租户配置范围和 API 资源,因为它们是单独的资源。

推测性地,如果您有一个集中式资源,将您的客户端点用作一种服务基础设施,您可以改为将您的预期租户指示为请求的一部分,并使用范围声明来确定请求是否被允许。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-20
    • 2019-12-05
    • 1970-01-01
    • 1970-01-01
    • 2022-01-24
    • 1970-01-01
    • 2012-11-13
    • 2019-03-26
    相关资源
    最近更新 更多