Dockerized SpringBoot oAuth2 with Spring Cloud Gateway

  docker, oauth, spring, spring-boot

I have a little project with 3 micro-services on of those service is the security one that implements Spring Security with OAuth2 everything behind a simple Spring Cloud Gateway

public RouteLocator myRoutes (
        RouteLocatorBuilder builder
) {
    return builder.routes()
            .route(p -> p.path("/auth/**")
                    .filters(f -> f.rewritePath("^/auth", ""))
                    .uri(authUri))
            .route(p -> p
                    .path("/payments/**")
                    .filters(f -> f.rewritePath("^/payments", ""))
                    .uri(paymentUri)
            )
            .route(p -> p
                    .path("/insurance/**")
                    .filters(f -> f.rewritePath("^/insurance", ""))
                    .uri(insuranceUri)
            )
            .build();
}

Everything works, my Javascript client calls the auth server that shows up a login page and redirect back with the accessToken.

Now, when i try to Dockerize all of this i have issues with Spring oauth/authorize redirect. Infact it used the container hostname… and not the gateway path, so basically this happens

the last one in my mind should be http://login.org.com/oauth/auhtorize.

What i’m doing wrong? Is there a way to prevent it use the container hostname?

Source: Docker Questions

LEAVE A COMMENT