Spring boot spring boot microservice docker实现中google oauth2的重定向uri参数无效
我正在使用SpringStack(SpringBoot2.0.0.RELEASE)创建一个站点,通过OAuth2将用户身份验证/注册委托给Google。它实现为几个Spring云微服务,在端口8080上运行一个Zuul网关Spring boot spring boot microservice docker实现中google oauth2的重定向uri参数无效,spring-boot,docker,oauth-2.0,microservices,netflix-zuul,Spring Boot,Docker,Oauth 2.0,Microservices,Netflix Zuul,我正在使用SpringStack(SpringBoot2.0.0.RELEASE)创建一个站点,通过OAuth2将用户身份验证/注册委托给Google。它实现为几个Spring云微服务,在端口8080上运行一个Zuul网关 Google Auth Server Zuul Gateway(:8080) / \ / \ / \ Other OAuth2 Client Microservice(
Google Auth Server
Zuul Gateway(:8080)
/ \
/ \
/ \
Other OAuth2 Client Microservice(:8000)
Microservices
我使用Google作为OAuth2服务器,使用spring-security-OAuth2作为客户端,它作为一个单独的微服务实现。如果我的所有云都部署在本地主机上,那么一切正常。但是如果我的微服务部署在不同的机器上,例如Docker,OAuth2登录就不起作用。获取无效的重定向Uri参数错误
Docker的Zuul配置:
zuul:
ignoredServices: '*'
host:
connection-timeout-millis: 20000
socket-timeout-millis: 20000 routes:
authserver_oauth:
path: /oauth2/**
serviceId: authserver
stripPrefix: false
sensitiveHeaders:
eureka:
instance:
prefer-ip-address: false
client:
serviceUrl:
defaultZone: http://eureka-server:8761/eureka/
spring:
security:
oauth2:
client:
registration:
google:
clientId: ***
clientSecret: ***
redirectUriTemplate: "{baseUrl}/oauth2/callback/{registrationId}"
scope:
- email
- profile
Docker的Eureka配置:
zuul:
ignoredServices: '*'
host:
connection-timeout-millis: 20000
socket-timeout-millis: 20000 routes:
authserver_oauth:
path: /oauth2/**
serviceId: authserver
stripPrefix: false
sensitiveHeaders:
eureka:
instance:
prefer-ip-address: false
client:
serviceUrl:
defaultZone: http://eureka-server:8761/eureka/
spring:
security:
oauth2:
client:
registration:
google:
clientId: ***
clientSecret: ***
redirectUriTemplate: "{baseUrl}/oauth2/callback/{registrationId}"
scope:
- email
- profile
Authserver配置:
zuul:
ignoredServices: '*'
host:
connection-timeout-millis: 20000
socket-timeout-millis: 20000 routes:
authserver_oauth:
path: /oauth2/**
serviceId: authserver
stripPrefix: false
sensitiveHeaders:
eureka:
instance:
prefer-ip-address: false
client:
serviceUrl:
defaultZone: http://eureka-server:8761/eureka/
spring:
security:
oauth2:
client:
registration:
google:
clientId: ***
clientSecret: ***
redirectUriTemplate: "{baseUrl}/oauth2/callback/{registrationId}"
scope:
- email
- profile
当我调试Oauth2条件时,请求和响应的uri不相等:
authorizationResponse.getRedirectUri()
(java.lang.String) http://authserver:8080/oauth2/callback/google
authorizationRequest.getRedirectUri()
(java.lang.String) http://localhost:8080/oauth2/callback/google
我在SpringBoot2.2.2RELEASE的云环境(NGINX、Docker、Cubernetes)中遇到了类似的问题,在云环境中,定制NGINX配置根本不是一个选项。尝试了一些方法,如设置x-forwarded-for属性、使用docker模拟prod、NGINX setup(),但都不起作用。最后,我将我的Spring boot版本更新为2.4.1,它在没有任何其他配置的情况下工作。Hi@Ashok,您是否已经找到了解决此问题的方法?我目前正与同样的情况作斗争。@GlabbichRulz见: