Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.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# 访问群体对identityserver4代码流访问令牌的声明错误_C#_Asp.net_Identityserver4_Openid Connect - Fatal编程技术网

C# 访问群体对identityserver4代码流访问令牌的声明错误

C# 访问群体对identityserver4代码流访问令牌的声明错误,c#,asp.net,identityserver4,openid-connect,C#,Asp.net,Identityserver4,Openid Connect,我正在为具有Identityserver4的vuejs客户端使用代码流。 我添加了RequirePkce,可以从oidc客户端获取访问令牌和id令牌。 但access tokenaud声明指向的是IdentityServer 4基址,而不是我的api资源。 会有什么不对劲吗 客户: new Client { ClientId = "js.admin", Client

我正在为具有Identityserver4的vuejs客户端使用代码流。 我添加了
RequirePkce
,可以从oidc客户端获取访问令牌和id令牌。 但access token
aud
声明指向的是IdentityServer 4基址,而不是我的api资源。 会有什么不对劲吗

客户:

new Client
                {
                    ClientId = "js.admin",
                    ClientName = "admin dashboard vuejs client.",

                    RequirePkce = true,
                    RequireClientSecret = false,
                    RequireConsent = false,
                    AllowedGrantTypes = GrantTypes.Code,
                    AllowAccessTokensViaBrowser = true,

                    RedirectUris = new List<string>
                    {
                        "http://localhost:8080",
                        "http://localhost:8080/logincb.html",
                        "http://localhost:8080/silent-renew.html"
                    },
                    PostLogoutRedirectUris = new List<string>
                    {
                        "http://localhost:8080/",
                        "http://localhost:8080"
                    },
                    AllowedCorsOrigins = new List<string>
                    {
                        "http://localhost:8080"
                    },
                    AllowedScopes = new List<string>
                    {
                        "openid",
                        "role",
                        "profile",
                        "api1.rw",
                        "email",
                        "phone"
                    }
                }
已解码的访问令牌:

 "iss": "http://localhost:5001",
 "aud": "http://localhost:5001/resources",
正如您所看到的,发行人和受众的声明都是相同的,但都是错误的

但即使是范围也是正确的。 我真的很感谢你的帮助

Bearer was not authenticated. Failure message: IDX10214: Audience validation failed. Audiences: 'http://localhost:5001/resources'. Did not match: validationParameters.ValidAudience: 'api1' or validationParameters.ValidAudiences: 'null'.

这是我最后一次出错。

http://localhost:5001/resources 是一种通用资源,当您尚未定义任何ApiResources或将其与请求的ApiScope关联时,将添加该资源

从文件中可以看出:

使用仅范围模型时,不会添加aud(观众)声明 由于此概念不适用,因此,请将其添加到令牌。如果你需要澳元 声明时,可以在上启用EmitStaticAudienceClaim设置 选项。这将在发卡机构名称/资源中发出aud索赔 格式。如果您需要更多地控制aud索赔,请使用API资源


要获得api1.rw作为您的受众,您需要在IdentityServer配置中添加ApiResource。您可以命名ApiResourceApiScopeapi1.rw

我没有输入代码,但我也定义了api资源。api1.rw是连接到api资源api1的我的apiscope。您可以将apiscope和ApiResource定义发布到您的问题中吗?您还可以设置此标志EmitStaticAudienceClaim(在IdentityServer中)设置为false以删除通用资源访问群体。我知道我可能看起来有点傻,但错误是由于向服务添加内存中api资源的错误方式所致。:)非常感谢你抽出时间。你救了我一天
Bearer was not authenticated. Failure message: IDX10214: Audience validation failed. Audiences: 'http://localhost:5001/resources'. Did not match: validationParameters.ValidAudience: 'api1' or validationParameters.ValidAudiences: 'null'.