Skip to content

Instantly share code, notes, and snippets.

@amoAHCP
Created May 2, 2016 19:30
Show Gist options
  • Save amoAHCP/b3509d859096952caf76f46665835525 to your computer and use it in GitHub Desktop.
Save amoAHCP/b3509d859096952caf76f46665835525 to your computer and use it in GitHub Desktop.
anauthorized acces when call http://localhost:8080/callback?redirect_uri=/private/somepage/test
OAuth2Auth authProvider = OAuth2Auth.create(vertx, OAuth2FlowType.AUTH_CODE, new JsonObject()
.put("clientID", "xxxx")
.put("clientSecret", "xxxx")
.put("site", "https://github.com/login")
.put("tokenPath", "/oauth/access_token")
.put("authorizationPath", "/oauth/authorize"));
// create a oauth2 handler on our domain: "http://localhost:8080"
OAuth2AuthHandler oauth2 = OAuth2AuthHandler.create(authProvider, "http://localhost:8080");
// these are the scopes
// oauth2.addAuthority("profile");
// setup the callback handler for receiving the GitHub callback
oauth2.setupCallback(router.get("/callback"));
// Serve the static private pages from directory 'private'
router.route("/private/*").handler(oauth2);
// mount some handler under the protected zone
router.route("/private/somepage/test").handler(rc -> {
final Session session = rc.session();
rc.response().end("Welcome to the protected resource! :\n\n"+rc.user().principal().encodePrettily());
});
router.get("/").handler(ctx -> {
ctx.response().putHeader("content-type", "text/html").end("Hello <br><a href=\"/private/\">Protected by Github</a>");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment