コード例 #1
0
  public void example3(Vertx vertx) {

    // Initialize the OAuth2 Library
    OAuth2Auth oauth2 = OAuth2Auth.create(vertx, OAuth2FlowType.PASSWORD);

    JsonObject tokenConfig =
        new JsonObject().put("username", "username").put("password", "password");

    // Callbacks
    // Save the access token
    oauth2.getToken(
        tokenConfig,
        res -> {
          if (res.failed()) {
            System.err.println("Access Token Error: " + res.cause().getMessage());
          } else {
            // Get the access token object (the authorization code is given from the previous step).
            AccessToken token = res.result();

            oauth2.api(
                HttpMethod.GET,
                "/users",
                new JsonObject().put("access_token", token.principal().getString("access_token")),
                res2 -> {
                  // the user object should be returned here...
                });
          }
        });
  }
コード例 #2
0
 public void example5(AccessToken token) {
   // Check if the token is expired. If expired it is refreshed.
   if (token.expired()) {
     // Callbacks
     token.refresh(
         res -> {
           if (res.succeeded()) {
             // success
           } else {
             // error handling...
           }
         });
   }
 }
コード例 #3
0
  public void example6(AccessToken token) {
    // Revoke only the access token
    token.revoke(
        "access_token",
        res -> {
          // Session ended. But the refresh_token is still valid.

          // Revoke the refresh_token
          token.revoke(
              "refresh_token",
              res1 -> {
                System.out.println("token revoked.");
              });
        });
  }