Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Identity Server 4与身份相关的作用域请求,但没有openid作用域_C#_Asp.net Core_Scope_Resources_Identityserver4 - Fatal编程技术网

C# Identity Server 4与身份相关的作用域请求,但没有openid作用域

C# Identity Server 4与身份相关的作用域请求,但没有openid作用域,c#,asp.net-core,scope,resources,identityserver4,C#,Asp.net Core,Scope,Resources,Identityserver4,我正在尝试添加一个自定义资源/范围,在我的测试中,我选择了它作为电子邮件,但据我所知,它可以是任何值。因此,对于我的资源,我有以下几点: return new List<IdentityResource> { new IdentityResources.OpenId(), new IdentityResources.Profile(), new IdentityResource("email", "Email", new [] { "email" })

我正在尝试添加一个自定义资源/范围,在我的测试中,我选择了它作为电子邮件,但据我所知,它可以是任何值。因此,对于我的资源,我有以下几点:

return new List<IdentityResource>
{
    new IdentityResources.OpenId(),
    new IdentityResources.Profile(),
    new IdentityResource("email", "Email", new [] { "email" })
    //new IdentityResources.Email()  -- This was tried as well, same error.
};

return new List<ApiResource> { new ApiResource("test", "Test") };
返回新列表
{
新标识资源.OpenId(),
新标识资源.Profile(),
新标识资源(“电子邮件”、“电子邮件”、新[]{“电子邮件”})
//new IdentityResources.Email()--也尝试了此操作,出现了相同的错误。
};
返回新列表{new ApiResource(“test”,“test”)};
然后,对于客户端上的作用域,其如下所示:

AllowedScopes = new List<string>
{
    "openid", "profile", "email", "test"
}
AllowedScopes=新列表
{
“openid”、“配置文件”、“电子邮件”、“测试”
}
但是,当我使用
http://localhost:5000/connect/authorize?Scope=test 电子邮件
我看到页面上的错误

2019-07-05 11:08:00.681-04:00[错误]无效范围:电子邮件
2019-07-05 11:08:00.684-04:00[错误]请求验证失败

我真的不确定哪里出了错。根据我找到的所有文档和帖子,这就是它的工作方式

编辑:存在一个被忽略的内部错误,导致传递错误的
列表。但是,即使解决了此问题,现在仍会出现另一条错误消息:

与标识相关的作用域请求,但没有openid作用域

编辑2:

在一些来自d_f的帮助后,我意识到我需要更新我的请求,现在看起来如下:

/连接/授权?范围=测试openid电子邮件和响应\u类型=id\u令牌和nonce=nonce


我现在获得授权,可以在声明中看到电子邮件范围。然而,即使我将电子邮件视为一个范围,我在声明中的任何地方都看不到实际的电子邮件。

电子邮件是标准的身份资源

试一试

返回新列表
{
新标识资源.OpenId(),
新标识资源.Profile(),
新的IdentityResources.Email()
}; 


如果要添加自定义的,可以找到它

您在
IdentityResource.Email()
声明中添加
IdentityResource
,这意味着
id\u token
将包含用户的电子邮件信息。您可以使用类似于检查返回的声明的在线工具对
id\u令牌
(非访问令牌)进行解码

您还可以在客户端配置中将
AlwaysIncludeUserClaimsInIdToken
设置为
true
,以查看它是否包含电子邮件声明:

new Client
{
    ClientId = "mvc",
    ClientName = "MVC Client",
    AllowedGrantTypes = GrantTypes.HybridAndClientCredentials,

    ....

    ....
    AlwaysIncludeUserClaimsInIdToken = true,
    AllowedScopes =
    {
        IdentityServerConstants.StandardScopes.OpenId,
        IdentityServerConstants.StandardScopes.Profile,
        "api1",
        IdentityServerConstants.StandardScopes.Email,
    },
    AllowOfflineAccess = true
},
此外,还有不同种类的IdentityServer 4快速启动示例(身份验证流):


您可以开始根据代码示例自定义客户端/IDS4。

我认为答案需要一些理论背景。 正如您可以在任何基础工作或原始版本中发现的那样,OpenID连接协议成为了OpenID和OAuth的组合。正如您在请求转换过程中看到的那样,OIdC与第二个兼容。OIdC的新功能是增加标识令牌。OAuth引入了access-aka-bearer-token+refresh-token,以便在现有的访问到期时获得一个新的访问令牌。所有这些都是关于使用承载授权http头访问API的。新的标识令牌表示应用程序的用户会话,而不是api

identity server 4中的
identity\u令牌
access\u令牌
的有效负载由两个单独的字典和相应的字典控制。不幸的是,您不能同时将作用域添加到两者中。但是您可以使用相同的声明定义两个不同的作用域。例如:


IdP的公共静态IEnumerable。要获取
id\u令牌中的所有用户声明
,您可以在IdSrv的客户端配置中设置
AlwaysIncludeUserClaimsInIdToken=true

我认为这不是问题所在,我可以将其切换到任何名称,并获得相同的问题。身份验证请求中缺少客户端id。您的代码中是否也缺少该错误,或者您只是删除了它以保持问题的干净性?我更新了我的问题,我解决了为什么会发生该特定错误,但现在取而代之的是另一个错误。您所说的授权请求是什么意思?你说哪个函数缺少id,我来检查一下?你的授权请求应该包含client_id{yourClientId}&scope=test email,但现在我看到了你更新的问题,我想这是另外一个问题。我以前从未见过这个错误,必须检查。@Bojan当您不请求openid作用域时,协议降级为oauth。这没关系,除非您请求任何标识作用域——openid connectyour请求添加的扩展错过了
openid
作用域。协议始终只要求
new Client
{
    ClientId = "mvc",
    ClientName = "MVC Client",
    AllowedGrantTypes = GrantTypes.HybridAndClientCredentials,

    ....

    ....
    AlwaysIncludeUserClaimsInIdToken = true,
    AllowedScopes =
    {
        IdentityServerConstants.StandardScopes.OpenId,
        IdentityServerConstants.StandardScopes.Profile,
        "api1",
        IdentityServerConstants.StandardScopes.Email,
    },
    AllowOfflineAccess = true
},