2016-07-06 194 views
0

有人可以幫我設置Oauth 2授權服務器Vert.x(3.3.0)。我沒有找到任何與它相關的文檔。 我發現vertx認證 - 這的oauth2模塊vert.x,但我想,如果授權服務器是不同 如Vert.x Oauth 2授權服務器

下面的代碼片段是vert.x文檔

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

// when there is a need to access a protected resource or call a protected method, 
// call the authZ url for a challenge 

String authorization_uri = oauth2.authorizeURL(new JsonObject() 
    .put("redirect_uri", "http://localhost:8080/callback") 
    .put("scope", "notifications") 
    .put("state", "3(#0/!~")); 

// when working with web application use the above string as a redirect url 

// in this case GitHub will call you back in the callback uri one should now complete the handshake as: 


String code = "xxxxxxxxxxxxxxxxxxxxxxxx"; // the code is provided as a url parameter by github callback call 

oauth2.getToken(new JsonObject().put("code", code).put("redirect_uri", "http://localhost:8080/callback"), res -> { 
    if (res.failed()) { 
    // error, the code provided is not valid 
    } else { 
    // save the token and continue... 
    } 
}); 

,它都將是有益的使用Github作爲授權服務器。我很想知道如何在vert.x中實現授權服務器,我知道spring security提供了這個功能,即Oauth2Server和OAuth2Client。

回答

3

Vert.x OAuth2只是一個OAuth2Client,沒有服務器實現,所以你不能從Vert.x項目本身獲取它。

Vert.x OAuth2用戶支持下面的流量:

  • 授權碼流(適用於應用與能夠存儲持久信息服務器)。
  • 密碼憑證流(當前一個流程無法使用或在開發過程中)。
  • 客戶端憑證流(僅使用它的客戶端證書,客戶端可以請求訪問令牌)
+0

你知道,如果隱流將在未來得到支持? – Skullcrasher

+0

你可以要求它在問題追蹤器上實現。然後根據路線圖和資源或社區拉請求,它可能在。 –