2016-09-28 104 views
0

我有一個Vertx oauth2的問題。在Vertx中 - 如何進行回調?

我跟着這個教程http://vertx.io/docs/vertx-web/java/#_oauth2authhandler_handler

OAuth2Auth authProvider = OAuth2Auth.create(vertx, OAuth2FlowType.AUTH_CODE, new OAuth2ClientOptions() 
    .setClientID("CLIENT_ID") 
    .setClientSecret("CLIENT_SECRET") 
    .setSite("https://github.com/login") 
    .setTokenPath("/oauth/access_token") 
    .setAuthorizationPath("/oauth/authorize")); 

// create a oauth2 handler on our domain: "http://localhost:8080" 
OAuth2AuthHandler oauth2 = OAuth2AuthHandler.create(authProvider, "http://localhost:8080"); 

// setup the callback handler for receiving the GitHub callback 
oauth2.setupCallback(router.get("/callback")); 

// protect everything under /protected 
router.route("/protected/*").handler(oauth2); 
// mount some handler under the protected zone 
router.route("/protected/somepage").handler(rc -> { 
    rc.response().end("Welcome to the protected resource!"); 
}); 

// welcome page 
router.get("/").handler(ctx -> { 
    ctx.response().putHeader("content-type", "text/html").end("Hello<br><a href=\"/protected/somepage\">Protected by Github</a>"); 
}); 

的想法是在受保護的文件夾都需要身份驗證的網頁。
當我想訪問受保護的網頁時,我被重定向到Microsoft登錄網站,登錄後我被重定向到我的回調。

我不明白的是如何處理回調呢? 我得到這樣的迴應:

https://localhost:8080/callback?code=AAABAAA...km1IgAA&session_state=.... 

如何理解(https://blog.mastykarz.nl/building-applications-office-365-apis-any-platform/)我需要以某種方式提取代碼和會話狀態和與後發回:

https://login.microsoftonline.com/common/oauth2/token 

在爲了得到令牌。

但我不明白Vertx如何做到這一點。 有什麼幫助嗎?如何提取代碼和會話併發送回Microsoft?

我在這裏找到了一些教程:https://github.com/vert-x3/vertx-auth/blob/master/vertx-auth-oauth2/src/main/java/examples/AuthOAuth2Examples.java但沒有幫助我。

我正在使用Azure身份驗證(在教程中寫入Github,但我將這一切都更改爲Microsoft)。

回答

0

您是否支持代理?回調處理程序將請求從應用程序發送到提供程序,而不是從瀏覽器發送。對我來說,這凍結了整個應用程序。您可以使用向OAuth2Auth.create提供的OAuth2ClientOptions設置代理