在ApiResource中使用的声明和IdentityServer4中的Scope之间有什么不同 [英] What is different between Claims used in ApiResource and Scope in IdentityServer4

查看:20
本文介绍了在ApiResource中使用的声明和IdentityServer4中的Scope之间有什么不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在IndetityServer4中创建了一个类似以下内容的ResourceApi

我定义了一个名为API 1的ApiResource,并为该API资源直接指定了Claims-name, sub,我扩展了该资源,指定了名为Api1.ReadApi1.Write的两个作用域,并为每个作用域指定了我需要的API特定部分的特定声明,但我不明白ApiResource和Scope中使用的声明有什么不同?

ApiResource中直接连接的ClaimsScope中使用的声明是什么意思?

我曾尝试仅在sub and name中限制sub and nameApiResource中的UserClaims,但如果我想在Api1.Write声明中role它在访问令牌中发送,但在Api1的定义中仅指定name and sub-为什么在ApiResource中定义UserClaims?

var apiResource = new ApiResource
            {
                Name = "Api1",
                UserClaims = new List<string> { "name", "sub" },

                Scopes = new List<Scope>
                {
                    new Scope
                    {
                        Name = "Api1.Read",
                        UserClaims = new List<string> {"sub", "name"}
                    },
                    new Scope
                    {
                        Name = "Api1.Write",
                        UserClaims = new List<string> {"sub", "name", "role"}
                    }
                }
            };

推荐答案

根据documentation on ApiResourceApiResource本身中的UserClaims将始终包含在访问令牌中。如果将API划分为多个Scope,则其中列出UserClaims将添加到ApiResource中指定的。

这篇关于在ApiResource中使用的声明和IdentityServer4中的Scope之间有什么不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆