jwt - 将 spring-security-oauth2 授权服务器与 kid 和 JWKS 一起使用?

标签 jwt spring-security-oauth2 jwk

按照文档 herethere ,我设法设置了一个授权服务器,它发出用非对称 key 签名的 JWT 访问 token ,资源服务器使用公钥的本地副本在本地验证这些 token 。到目前为止一切顺利。

我的最终目标是让资源服务器使用授权服务器上的 JWKS 端点,并使用 JWT 中的“kid” header 在 JWKS 中查找正确的 key 并在本地验证,支持 key 轮换。 我找到了 how to make the Authorization Server expose a JWKS endpoint , 还有 how to specify the key-set-uri for the resource server .

不过好像也没有办法

  • 在 JWKS 中发布 kid(key id)值
  • 在 JWT 中包含 kid header

有办法吗?

最佳答案

我找到了一种在 jwks 端点中设置 child 的方法:

@FrameworkEndpoint
public class JwkSetEndpoint {
    private final KeyPair keyPair;

    public JwkSetEndpoint(KeyPair keyPair) {
        this.keyPair = keyPair;
    }

    @GetMapping("/.well-known/jwks.json")
    @ResponseBody
    public Map<String, Object> getKey() {
        RSAPublicKey publicKey = (RSAPublicKey) this.keyPair.getPublic();
        RSAKey key = new RSAKey.Builder(publicKey)
                .keyID("YOUR_KID_HERE")
                .keyUse(KeyUse.SIGNATURE).build();
        return new JWKSet(key).toJSONObject();
    }
}

我没有找到在JWT header中设置它的方法。

关于jwt - 将 spring-security-oauth2 授权服务器与 kid 和 JWKS 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53982192/

相关文章:

java - Spring 安全访问控制允许来源 : * (CORS) issue on invalid JWT token

node.js - 在 Mocha 上测试管理员用户

java - Spring WebClient 和 client_credentials 授予

Spring oauth2 添加表前缀名称

java - 如何修复 spring security oauth 中不安全的 jwt-set-uri?

javascript - 在我的 Angular 2 应用程序中使用 JWT 并将其存储在 localStorage 中。但是,当该项目不存在时我该如何处理?

c# - JWT token 过期在 Asp.Net Core API 中不起作用?

azure - 使用 AZURE B2C 身份验证的 Spring Boot OAuth2 服务器

go - 如何在 Go 中使用 JWK 验证 JWT 签名?