繁体   English   中英

对 identityserver4 代码流访问令牌的受众声明是错误的

[英]Audience claim on identityserver4 code flow access token is wrong

我正在为带有 Identityserver4 的 vuejs 客户端使用代码流。 我添加了RequirePkce ,我可以从 oidc-client 获取访问令牌和 id 令牌。 但访问令牌aud声明指向 Identityserver4 基地址,而不是我的 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"
                    }
                }

oidc 客户端设置:

const clientSettings = {
      userStore: new WebStorageStateStore({ store: window.localStorage }),
      authority: STS_DOMAIN,
      client_id: "js.admin",
      redirect_uri: "http://localhost:8080/logincb.html",
      automaticSilentRenew: true,
      silent_redirect_uri: "http://localhost:8080/silent-renew.html",
      response_type: "code",
      scope: "openid profile api1.rw role email phone",
      post_logout_redirect_uri: "http://localhost:8080/",
      filterProtocolClaims: true
    };

访问令牌解码:

 "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 关联时添加。

这里的文档中,它说:

当使用仅限范围的 model 时,不会将任何 aud(观众)声明添加到令牌中,因为此概念不适用。 如果您需要 aud 声明,您可以在选项上启用 EmitStaticAudienceClaim 设置。 这将以 issuer_name/resources 格式发出 aud 声明。 如果您需要对 aud 声明进行更多控制,请使用 API 资源。

要将api1.rw作为您的受众,您需要将ApiResource添加到您的 IdentityServer 配置中。 您可以将ApiResourceApiScope命名为api1.rw

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM