I'm using spring stack (Spring Boot 2.0.0.RELEASE) for creating a site that delegues user authentication/registration to Google via OAuth2. It is implemented as a few Spring Cloud microservices with a Zuul gateway running on port 8080.
Google Auth Server
Zuul Gateway(:8080)
/ \
/ \
/ \
Other OAuth2 Client Microservice(:8000)
Microservices
I use Google as an OAuth2 server, and use spring-security-oauth2 as a client, which is implemented as a separate microservice. If all my cloud is deployed at localhost everything works fine. But if my microservices are deployed at different machines, e.g. Docker, OAuth2 login doesn't work. getting invalid redirect Uri parameter error.
Zuul configuration for Docker:
zuul:
ignoredServices: '*'
host:
connection-timeout-millis: 20000
socket-timeout-millis: 20000 routes:
authserver_oauth:
path: /oauth2/**
serviceId: authserver
stripPrefix: false
sensitiveHeaders:
Eureka Configuration for Docker:
eureka:
instance:
prefer-ip-address: false
client:
serviceUrl:
defaultZone: http://eureka-server:8761/eureka/
Authserver configuration:
spring:
security:
oauth2:
client:
registration:
google:
clientId: ***
clientSecret: ***
redirectUriTemplate: "{baseUrl}/oauth2/callback/{registrationId}"
scope:
- email
- profile
When I debug for Oauth2 condition I am getting unequal uri for request and response:
authorizationResponse.getRedirectUri()
(java.lang.String) http://authserver:8080/oauth2/callback/google
authorizationRequest.getRedirectUri()
(java.lang.String) http://localhost:8080/oauth2/callback/google