在反应式spring webflux服务中,我将端点配置为受OAuth2资源服务器保护。当我第一次启动服务器时,它会正确验证Bearer令牌,但是大约30秒后,完全相同的请求开始失败,并显示以下错误:
error="invalid_token"
error_description="This iss claim is not equal to the configured issuer"
error_uri="https://tools.ietf.org/html/rfc6750#section-3.1"
我已验证令牌有效,并且iss
声明与spring.security.oauth2.resourceserver.jwt.issuer-uri
中配置的声明相同。如果配置不正确,那么我将没有有效的请求。
经过仔细检查,我发现错误是由于URL
声明与预期URL的iss
比较引起的,因为前30秒InetAddress.getAddress()
匹配,但是不匹配。这使用的是Azure AD提供程序终结点https://sts.windows.net/{{tenantId}}/
,并且我已验证URL 字符串是否匹配,只是内部地址不匹配。可能是什么原因造成的?在最初的30秒后,如何与有效的发行者一起验证令牌?谢谢。
作为参考,这是我的SecurityWebFilterChain
:
@Bean
public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
return http
.csrf().disable()
.authorizeExchange().anyExchange().authenticated()
.and().oauth2ResourceServer().jwt().and()
.and().build();
}
包括的分级实现:
org.springframework.boot:spring-boot-starter-security:2.1.0.RC1
org.springframework.boot:spring-boot-starter-webflux:2.1.0.RC1
org.springframework.security:spring-security-oauth2-resource-server:5.1.1.RELEASE
org.springframework.security:spring-security-oauth2-jose:5.1.1.RELEASE