[英]Vert.x Oauth 2 Authorization server
有人可以幫我設置Oauth 2授權服務器Vert.x(3.3.0)。我沒有找到與其相關的任何文檔。 我在這個vert.x模塊中找到了vertx-auth-oauth2,但是我想如果授權服務器不同,它將很有用,例如
以下代碼段來自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。
Vert.x OAuth2只是一個OAuth2Client,沒有服務器實現,因此您無法從Vert.x項目本身獲取它。
Vert.x OAuth2支持以下流程:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.