我在设置一个小环境时遇到问题,我有一个 Spring Cloud Gateway,它使用 Keycloak 服务器进行身份验证,然后在成功身份验证后将请求重定向到后端服务。
当我尝试使用我的 Keycloak 服务器对来自我的 Spring Cloud Gateway 的用户进行身份验证时,该服务器具有到 Azure AD 的用户链接,浏览器/Spring Cloud Gateway 不会重定向回原始 URL。
我认为这是因为我没有正确维护 redirect-uri 但我不知道我应该在那里写什么。我用我的开放 api 端点 '/login' 尝试了它,但随后我被重定向到该登录页面,而不是调用的原始 URL。
任何帮助将不胜感激。
我在容器中运行 Keycloak 服务器。它被设置为使用自签名证书。
一个。我创造了一个新领域
c。我添加了一个指向 Azure AD 的 OIDC 身份提供程序。
Azure Ad 有一个有效的重定向 URI 到我的 Keycloak:
这是有效的,因为我检查了身份验证是否使用 Postman 返回了有效的 JWT。
安全配置:
@Configuration
public class GatewayConfig {
@Bean
public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
return http.authorizeExchange().pathMatchers("/login**").permitAll().pathMatchers("/**").authenticated().and()
.oauth2Login().and().build();
}
}
应用程序.yml
spring:
profiles: prod
security:
oauth2:
client:
registration:
oauth:
client-id: ${CLIENT_ID:LPMESPlus}
client-secret: ${CLIENT_SECRET:LB8OLfamCKhIGZWb6qw5N6gX1DVUMAUh}
scope:
- ${CLIENT_SCOPE:openid}
- LPMESPlus
redirect-uri: ${REDIRECT_URI:**???**}
authorization-grant-type: ${AUTHORIZATION_GRANT_TYPE:authorization_code}
client-name: ${CLIENT_NAME:Keycloak}
provider:
oauth:
authorization-uri: ${AUTH_URI}
token-uri: ${TOKEN_URI}
user-info-uri: ${USER_INFO_URI}
user-name-attribute: ${USER_NAME_ATTRIBUTE}
jwk-set-uri: ${JWT_SET_URI}
issuer-uri: ${ISSUER_URI}
有人能告诉我如何维护正确的重定向 uri,我是否必须将其添加为 keycloaks openid connect 客户端主页 url?