2016-07-06 192 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

你可以要求它在问题追踪器上实现。然后根据路线图和资源或社区拉请求,它可能在。 –