在网关/代理后配置Spring Security OIDC/OAuth2

nbysray5  于 2022-11-23  发布在  Spring
关注(0)|答案(1)|浏览(125)

我在一个Spring Boot微服务中遇到了一个关于Spring Security中令牌解密部分的问题。基本上发生了以下问题:在@AuthenticationPrincipal Jwt jwt上调用getSubject()方法时发生以下错误

Caused by: java.lang.IllegalStateException: The Issuer "https://ids-for-spid.aqp.it:443/oauth2/token" provided in the configuration did not match the requested issuer "https://clidens1.aqp.it:9443/oauth2/token"

我猜想这是由于以下条件造成的:在一个众所周知的文件中,有一个发行者的url基础与传递给库的url基础不同(我猜是因为有一个代理或网关),我该如何解决以下问题?
Specifically, the url to access the well-known file is the following https://clidens1.aqp.it:9443/oauth2/token/.well-known/openid-configuration ed and inside there is the following issuer https://ids-for-spid.aqp.it/oauth2/token , which differs from the base url clidens1.aqp.it on which I have the only accessibility.

cbjzeqam

cbjzeqam1#

在JWT验证过程中,将根据conf中的发布者URI检查标记iss声明。它必须完全匹配(即使尾部有斜杠也很重要)。
对于令牌验证,还需要授权服务器公钥。它是使用JWK-set URI提取的,通常可以在OIDC配置中找到,它本身通常可以从iss声明值推导出的位置获得。
如果在iss声明中声明的主机无法从resource-server访问,您是否也尝试过设置JWK-set URI属性?

# this must be the exact iss claim value
spring.security.oauth2.resourceserver.jwt.issuer-uri=https://clidens1.aqp.it:9443/oauth2/token

# actual value to use is the "jwks_uri" in https://clidens1.aqp.it:9443/oauth2/token/.well-known/openid-configuration
# with hostname and port reachable from resource-server (spring-app this properties file belongs to)
spring.security.oauth2.resourceserver.jwt.jwk-set-uri=https://ids-for-spid.aqp.it:9443/oauth2/token/protocol/openid-connect/certs

如果任何人都无法访问iss声明中的此主机名,您是否尝试过配置授权服务器以更改iss声明的值?
在Keycloak中设置hostname配置属性可以解决您的问题,但是您显然使用了另一个授权服务器。

相关问题