在遇到同样的问题时,我偶然发现了这篇文章。所以我希望它对某人有用。我不认为这是最好的解决方案,所以也许有人想出了一个更好的答案,我希望例如设置一些外部 bean。
背景:Jwk 存储正在将令牌标头中的 KID 与内存中的 KID 进行比较,如果不可用,它将请求众所周知的端点
因此,将 KID 放入 JwkSetEndpoint 会生成一个包含 child 的 json 文件。在此旁边,您需要获取 jwt 令牌标头上的 KID。
我在课堂上的解决方案扩展了 JwtAccessTokenConverter
@Override
protected String encode(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
String content = null;
try {
content = objectMapper.formatMap(getAccessTokenConverter().convertAccessToken(accessToken, authentication));
} catch (Exception e) {
throw new IllegalStateException("Cannot convert access token to JSON", e);
}
Map<String, String> headers = getJwtHeader();
String token = JwtHelper.encode(content, signer, headers).getEncoded();
return token;
}
在 KID 标头旁边,Tokenstore 期望使用标头设置为签名。我还必须覆盖签名者对象,因为我被 hmac 签名者而不是所需的 RsaSigner 卡住了。