【发布时间】:2020-02-05 22:31:48
【问题描述】:
我已经使用授权码 + PKCE 与客户端一起设置了 IdentityServerV4,并将访问令牌类型设置为引用。
new Client
{
ClientId = "app",
ClientName = "My Application",
AllowedGrantTypes = GrantTypes.Code,
RequireClientSecret = false,
RedirectUris = { "http://site.example.com:3000/callback" },
AllowedCorsOrigins = { "http://site.example.com:3000" },
AllowedScopes = { "openid", "profile", "email" },
AccessTokenType = AccessTokenType.Reference,
RequireConsent = false,
RequirePkce = true
}
我现在想在客户端应用程序和服务之间设置一个反向代理网关,该网关将在转发请求之前将参考令牌交换为常规签名的 JWT。在设置网关之前,我尝试通过使用从登录获得的参考令牌调用自省端点来手动执行交换。
我向身份服务器as described here 添加了一个我称为“网关”的 API,给了它一个秘密,并使用带有 API 的 ID 和秘密的 IntrospectionClient 成功调用了这个端点,但我得到了一个活动的响应: false,并且身份服务器日志显示令牌缺少预期范围“网关”的错误。日志中显示的token信息只显示openid范围。
new ApiResource("gateway"){
ApiSecrets = { new Secret("test".Sha256()) }
}
这会导致来自 IdentityServer 的两条日志消息:
fail: IdentityServer4.ResponseHandling.IntrospectionResponseGenerator[0]
Expected scope gateway is missing in token
info: IdentityServer4.Endpoints.IntrospectionEndpoint[0]
Success token introspection. Token active: True, for API name: gateway
所以我从中得出的结论是,API 和发出的令牌之间缺少一些链接,但我已经尝试了我能想到的 Client 和 ApiResource 定义之间的所有范围排列和允许范围,但我似乎无法得到预期的结果。我已经多次阅读和重读文档,但在这种情况下我无法完全弄清楚 API 和客户端之间的关系。需要什么样的配置来支持这种类型的设置?
【问题讨论】:
标签: oauth-2.0 jwt identityserver4 openid-connect