我有一个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)。