我有一个openid提供者(openam)在本地运行。我使用的是一个自签名证书,jwks url是@ https://localhost:8443/openam/oauth2/connect/。
由于ssl证书是自签名的,所以在解码oidc令牌时,我将得到一个SSLHandshake异常。我尝试使用自定义rest模板,方法是创建一个自定义JwtDecoder (如https://docs.spring.io/spring-security/site/docs/current/reference/html5/#oauth2resourceserver-jwt-decoder-dsl中所建议的)
@Bean
public JwtDecoder jwtDecoder() {
NimbusJwtDecoder.withJwkSetUri("https://localhost:8443/openam/oauth2/connect").restOperations(myCustomRestTemplateThatAllowsSelfSignedCerts()).build();
}但是这个解码器似乎没有被使用。正在使用OidcIdTokenDecoderFactory来创建解码器。这个类似乎不允许我们传递自定义的jwtDecoder。
为什么oauthResourceServer().jwt().decoder(customDecoder())不能工作?如何让解码器使用具有自签名证书的网站jwks uri?
我正在考虑的一个选项是将自签名证书添加到我的jdk的仙人掌文件夹中。
发布于 2020-01-15 17:04:49
OAuth2LoginAuthenticationFilter正在调用OidcAuthorizationCodeAuthenticationProvider进行OpenID身份验证。要更改它使用的JwtDecoder,您应该有一个JwtDecoderFactory bean。
例如,您可能有如下内容:
@Bean
public JwtDecoderFactory<ClientRegistration> customJwtDecoderFactory() {
return new CustomJwtDecoderFactory();
}
static class CustomJwtDecoderFactory implements JwtDecoderFactory<ClientRegistration> {
public JwtDecoder createDecoder(ClientRegistration reg) {
//...
return new CustomJwtDecoder();
}
}希望这至少能部分回答你的问题。
https://stackoverflow.com/questions/59744791
复制相似问题