Silent failure to send backend request after authentication with OAuth2
@tsegismont is already working on this.
Since Oct 25, 2024.
Assessment
This issue has not been assessed yet.
Description
When the Vert.x Web Proxy handler is installed after an OAuth2 handler, the proxy silently fails to send the request to the backend just after authentication.
If the user is already authenticated with the OAuth2 provider, the proxy successfully sends the request.
Here's an example setup:
router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)));
OAuth2Auth authProvider = GithubAuth.create(vertx, clientId, clientSecret);
router.route("/protected").handler(OAuth2AuthHandler.create(vertx, authProvider, "http://localhost:4180/oauth2/callback")
.setupCallback(router.route("/oauth2/callback"))
.withScope("user:email"));
router.route("/protected").handler(rc -> {
Context context = vertx.getOrCreateContext();
User user = rc.user();
Session session = rc.session();
JsonObject userInfo = session.get("userInfo");
if (userInfo == null) {
authProvider.userInfo(user).onComplete(ar -> {
if (ar.succeeded()) {
session.put("userInfo", ar.result());
context.putLocal("userInfo", ar.result());
context.putLocal("accessToken", user.get("access_token"));
rc.next();
} else {
session.destroy();
rc.fail(ar.cause());
}
});
} else {
context.putLocal("userInfo", userInfo);
context.putLocal("accessToken", user.get("access_token"));
rc.next();
}
});
HttpClient proxyClient = vertx.createHttpClient();
HttpProxy httpProxy = HttpProxy.reverseProxy(proxyClient)
.addInterceptor(new ProxyInterceptor() {
@Override
public Future<ProxyResponse> handleProxyRequest(ProxyContext pc) {
ProxyRequest proxyRequest = pc.request();
MultiMap headers = proxyRequest.headers();
headers.remove("Cookie");
Context context = vertx.getOrCreateContext();
JsonObject userInfo = context.getLocal("userInfo");
if (userInfo != null) {
headers.set("X-Forwarded-User", userInfo.getString("login"));
headers.set("X-Forwarded-Email", userInfo.getString("email"));
headers.set("X-Forwarded-Access-Token", context.<String>getLocal("accessToken"));
}
return pc.sendRequest();
}
});
router.route().handler(ProxyHandler.create(httpProxy, 8080, "localhost"));
With debugging, it appears that when the proxy sets up the pipe on the incoming request, no callback is invoked:
- Dominant language
- Java
- Stars
- 68
- Forks
- 37
- Avg merge
- 8m
- Merged PRs (30d)
- 1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from eclipse-vertx/vertx-http-proxy
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 35/100
eclipse-vertx/vertx-http-proxy#139 · 3 comments ·
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 45/100
eclipse-vertx/vertx-http-proxy#137 · 2 comments ·
-
documentation enhancement help wanted
Difficulty 4/5 3-5 days Newbie friendliness 35/100
eclipse-vertx/vertx-http-proxy#124 · 3 comments ·
-
enhancement
eclipse-vertx/vertx-http-proxy#114 · 2 comments · 1 assignee ·
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 30/100
eclipse-vertx/vertx-http-proxy#109 · 5 comments ·
All issues in eclipse-vertx/vertx-http-proxy
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
infinispan/infinispan#18150 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
opensearch-project/k-NN#3597 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100