Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web ReverseProxy fails after authentication with OAuth2 callback #2664

Closed
skoya opened this issue Oct 21, 2024 · 1 comment
Closed

Web ReverseProxy fails after authentication with OAuth2 callback #2664

skoya opened this issue Oct 21, 2024 · 1 comment

Comments

@skoya
Copy link

skoya commented Oct 21, 2024

Questions

Version

4.5.10

Context

I encountered an exception which looks suspicious while .

I setup OAuth2 and then tried to proxy. Everything looks okay but then the proxied request failed after a time out. Commenting out all the OAuth2 code and it works fine as a reverse proxy.

Do you have a reproducer?

v = Vertx.vertx();

        HttpClient proxyClient = v.createHttpClient();
        HttpProxy httpProxy = HttpProxy.reverseProxy(proxyClient);
        Router proxyRouter = Router.router(v);
        
        HttpServer proxyServer = v.createHttpServer();

        OAuth2Auth authProvider = AzureADAuth.create(v, "CLIENT_ID", "CLIENT_SECRET", "TENANT");
        OAuth2AuthHandler oauth2 = OAuth2AuthHandler.create(v, authProvider, "http://localhost:8201/callback/");

        oauth2.setupCallback(proxyRouter.route("/callback/"));

        proxyRouter.route().handler(ctx -> {
            System.out.println("Global handler: Request path = " + ctx.request().path());
            ctx.next();  // Pass request to the next handler in the chain
        });

        proxyRouter.route("/*").handler(oauth2);

        proxyRouter.route("/*").handler(ctx-> {
            if (ctx.user() == null) {
                System.out.println("OAuth2 Auth handler triggered for path: " + ctx.request().path());
                oauth2.handle(ctx);
            } else {
                System.out.println("User authenticated: " + ctx.user().principal());
                ctx.next();
            }
        });
        proxyRouter.route(HttpMethod.GET, "/*").handler(ProxyHandler.create(httpProxy, 8200, "localhost"));

        proxyServer.requestHandler(proxyRouter).listen(8201);   

Steps to reproduce

  1. Create an app registration in Azure AD
  2. Create any webserver as an Origin for the reverse proxy to hit on port 8200
  3. Spin up the above code and http http://localhost:8201 (proxy server address).
  4. Login with Azure Oauth 2 creds
  5. Callback is called, but then the proxy handler timesout.
  6. Comment out all the OAuth2 code and the reverse proxy works fine!

Extra

I am using Windows 11 H2. Not sure if there is any weirdness with DNS.

@skoya skoya added the bug label Oct 21, 2024
@skoya skoya changed the title Web Proxy fails after authentication with OAuth2. Web ReverseProxy fails after authentication with OAuth2 callback Oct 21, 2024
@tsegismont
Copy link
Contributor

tsegismont commented Oct 28, 2024

Duplicates eclipse-vertx/vertx-http-proxy#101

@tsegismont tsegismont closed this as not planned Won't fix, can't repro, duplicate, stale Oct 28, 2024
@tsegismont tsegismont added duplicate and removed bug labels Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants