Skip to content

Instantly share code, notes, and snippets.

@hakansakalli
Forked from thomasreinecke/MainVerticle.java
Created February 17, 2019 21:28
Show Gist options
  • Select an option

  • Save hakansakalli/e9f5642c2ee0306f82dfa66ab69290ac to your computer and use it in GitHub Desktop.

Select an option

Save hakansakalli/e9f5642c2ee0306f82dfa66ab69290ac to your computer and use it in GitHub Desktop.
OpenIDConnectAuth.discover(
vertx,
new OAuth2ClientOptions()
.setClientID("<your google auth client id>")
.setClientSecret("<your google auth client secret>")
.setSite("https://accounts.google.com")
.setTokenPath("https://www.googleapis.com/oauth2/v3/token")
.setAuthorizationPath("/o/oauth2/auth"),
res -> {
if (res.succeeded()) {
// the setup call succeeded. At this moment your auth is ready to use and google signature keys
// are loaded so tokens can be decoded and verified.
System.out.println("Google OAUth2 setup successful !");
googleOAuth2Provider = res.result();
// get some information about the oauth2 flow and print it out
OAuth2FlowType flowType = googleOAuth2Provider.getFlowType();
System.out.println("Flow Type: "+flowType);
// setup the oauth2 handler, make sure it calls back to the frontend app and add the "profile" authority
googleOAuth2Handler = OAuth2AuthHandler.create(googleOAuth2Provider, "http://localhost:8081/callback");
Set<String> authorities = new HashSet<String>();
authorities.add("profile");
googleOAuth2Handler.addAuthorities(authorities);
googleOAuth2Handler.setupCallback(router.get("/callback"));
} else {
// the setup failed.
System.err.println("Google OAUth2 setup failed !");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment