簡體   English   中英

Vertx-使用OAuth2保護路由時缺少GET參數

[英]Vertx - missing GET parameters while securing route using OAuth2

我遵循了使用OAuth2和GitHub提供程序來保護路由的示例: http : //vertx.io/docs/vertx-web/java/#_oauth2authhandler_handler ,除了請求重定向后缺少GET參數外,它工作正常。

我的代碼:

public class MyVerticle extends AbstractVerticle {
    @Override
    public void start() throws Exception {
        HttpServer server = vertx.createHttpServer();
        Router router = Router.router(vertx);

        OAuth2Auth authProviderGitHub = GithubAuth.create(vertx, "<CLIENT_ID>", "<CLIENT_SECRET>");

        OAuth2AuthHandler oauth2 = OAuth2AuthHandler.create(authProviderGitHub, "http://localhost:8080/callback"); 

        oauth2.setupCallback(router.route());

        router.route("/protected/*").handler(oauth2);

        Handler<RoutingContext> requestHandler = (routingContext) -> {
            String paramValue = routingContext.request().getParam("param");
            routingContext.response().end("PARAM: " + paramValue);
        };

        router.get("/endpoint").handler(requestHandler);
        router.get("/protected/endpoint").handler(requestHandler);

        server.requestHandler(router::accept).listen(8080);
    }
}

我有兩個簡單的端點:

/endpoint     // public, without protection

/protected/endpoint // protected with OAuth2

當我從瀏覽器/端點調用

 http://localhost:8080/endpoint?param=foo 

它按預期工作並返回PARAM:foo ,而當我用

http://localhost:8080/protected/endpoint?param=foo

它正確地將我重定向到GitHub登錄頁面,然后將查詢返回到我的處理程序,但沒有GET參數,因此來自端點的響應為PARAM:null

知道我在做什么錯嗎?

在vert.x <= 3.4.2上,僅將路徑用於重定向,對3.5系列進行了改進,可以依賴完整的uri,因此您的代碼將在該版本上運行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM