【发布时间】:2021-06-11 11:31:22
【问题描述】:
我正在使用带有 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'.
这是我得到的最后一个错误。
【问题讨论】:
标签: c# asp.net identityserver4 openid-connect