正在缓存 json 个从 openid 连接元数据端点获取的 Web 密钥

caching json web keys got from openid connect metadata endpoint

Azure AD B2C 有一个 OpenID Connect 元数据终结点,它允许应用程序在运行时获取信息。此端点具有有关令牌签名密钥、令牌内容的信息,endpoints.I 需要查询此端点以获取 jwk_uris。 jwk_uri 具有用于签署 jwt 的密钥的 uri。我需要将这些密钥缓存不超过 24 小时。谁能建议我如何在 Spring 中做到这一点?有没有支持这个的api?

使用 spring 框架的可能解决方案是将调度程序和缓存结合起来:

HttpsJwks will cache keys for a time period based on the cache directive headers or the http response or setDefaultCacheDuration(long defaultCacheDuration),如果响应的缓存指令 headers 不存在或指示不应缓存内容。

HttpsJwks object 可以与 JwtConsumer/JwtConsumerBuilder and HttpsJwksVerificationKeyResolver 结合使用,如果遇到 [=11],也会重新调用 jwk_uri 并重新启动缓存=](密钥 ID)在 JWT 中,不在缓存的密钥集中。