Examples of GoogleOAuthHelper


Examples of com.google.gdata.client.authn.oauth.GoogleOAuthHelper

        throw new IllegalArgumentException("Invalid Signature Method");
    }

    // Finally create a new GoogleOAuthHelperObject.  This is the object you
    // will use for all OAuth-related interaction.
    GoogleOAuthHelper oauthHelper = new GoogleOAuthHelper(signer);


    ////////////////////////////////////////////////////////////////////////////
    // STEP 3: Get the Authorization URL
    ////////////////////////////////////////////////////////////////////////////

    // Set the scope for this particular service.
    oauthParameters.setScope(variables.getScope());

    // This method also makes a request to get the unauthorized request token,
    // and adds it to the oauthParameters object, along with the token secret
    // (if it is present).
    oauthHelper.getUnauthorizedRequestToken(oauthParameters);

    // Get the authorization url.  The user of your application must visit
    // this url in order to authorize with Google.  If you are building a
    // browser-based application, you can redirect the user to the authorization
    // url.
    String requestUrl = oauthHelper.createUserAuthorizationUrl(oauthParameters);
    System.out.println(requestUrl);
    System.out.println("Please visit the URL above to authorize your OAuth "
        + "request token.  Once that is complete, press any key to "
        + "continue...");
    System.in.read();


    ////////////////////////////////////////////////////////////////////////////
    // STEP 4: Get the Access Token
    ////////////////////////////////////////////////////////////////////////////

    // Once the user authorizes with Google, the request token can be exchanged
    // for a long-lived access token.  If you are building a browser-based
    // application, you should parse the incoming request token from the url and
    // set it in GoogleOAuthParameters before calling getAccessToken().
    String token = oauthHelper.getAccessToken(oauthParameters);
    System.out.println("OAuth Access Token: " + token);
    System.out.println();


    ////////////////////////////////////////////////////////////////////////////
    // STEP 5: Make an OAuth authorized request to Google
    ////////////////////////////////////////////////////////////////////////////

    // Initialize the variables needed to make the request
    URL feedUrl = new URL(variables.getFeedUrl());
    System.out.println("Sending request to " + feedUrl.toString());
    System.out.println();
    GoogleService googleService =
        new GoogleService(variables.getGoogleServiceName(), "oauth-sample-app");

    // Set the OAuth credentials which were obtained from the step above.
    googleService.setOAuthCredentials(oauthParameters, signer);

    // Make the request to Google
    BaseFeed resultFeed = googleService.getFeed(feedUrl, Feed.class);
    System.out.println("Response Data:");
    System.out.println("=====================================================");
    System.out.println("| TITLE: " + resultFeed.getTitle().getPlainText());
    if (resultFeed.getEntries().size() == 0) {
      System.out.println("|\tNo entries found.");
    } else {
      for (int i = 0; i < resultFeed.getEntries().size(); i++) {
        BaseEntry entry = (BaseEntry) resultFeed.getEntries().get(i);
        System.out.println("|\t" + (i + 1) + ": "
            + entry.getTitle().getPlainText());
      }
    }
    System.out.println("=====================================================");
    System.out.println();


    ////////////////////////////////////////////////////////////////////////////
    // STEP 6: Revoke the OAuth token
    ////////////////////////////////////////////////////////////////////////////

    System.out.println("Revoking OAuth Token...");
    oauthHelper.revokeToken(oauthParameters);
    System.out.println("OAuth Token revoked...");
  }
View Full Code Here

Examples of com.google.gdata.client.authn.oauth.GoogleOAuthHelper

    oauthParameters.setOAuthConsumerSecret(variables.getSignatureKey());
    OAuthSigner signer = new OAuthHmacSha1Signer();

    // Finally create a new GoogleOAuthHelperObject.  This is the object you
    // will use for all OAuth-related interaction.
    GoogleOAuthHelper oauthHelper = new GoogleOAuthHelper(signer);


    ////////////////////////////////////////////////////////////////////////////
    // STEP 3: Make a request to Google
    ////////////////////////////////////////////////////////////////////////////
View Full Code Here

Examples of com.google.gdata.client.authn.oauth.GoogleOAuthHelper

   *
   * @return URL, that user must follow to start registration
   * @throws OAuthException
   */
  public String getUserAuthorizationUrl() throws OAuthException{
    GoogleOAuthHelper googleOAuthHelper = getOAuthHelper(true);
      GoogleOAuthParameters googleOAuthParameters = getOAuthParameter(true);
      googleOAuthHelper.getUnauthorizedRequestToken(googleOAuthParameters);
    String requestUrl = googleOAuthHelper.createUserAuthorizationUrl(googleOAuthParameters);
    return requestUrl;
  }
View Full Code Here

Examples of com.google.gdata.client.authn.oauth.GoogleOAuthHelper

   * @return List<String>, where 1st element is Access Token, 2nd element is Token Secret
   * @throws OAuthException
   */
  public List<String> getAccessToken() throws OAuthException{
    List<String> accessTokenAndSecret = new ArrayList<String>();
    GoogleOAuthHelper googleOAuthHelper = getOAuthHelper(false);
      GoogleOAuthParameters googleOAuthParameters = getOAuthParameter(false);
    accessTokenAndSecret.add(googleOAuthHelper.getAccessToken(googleOAuthParameters));
    accessTokenAndSecret.add(googleOAuthParameters.getOAuthTokenSecret());
    return accessTokenAndSecret;
 
View Full Code Here

Examples of com.google.gdata.client.authn.oauth.GoogleOAuthHelper

   * @param getNew if true, new OAuth helper will be returned, existing otherwise
   * @return OAuth Helper with specified URLs for request Token, Access Token, User auth URL
   */
  private GoogleOAuthHelper getOAuthHelper(boolean getNew){
    if (getNew){
        oauthHelper = new GoogleOAuthHelper(new OAuthHmacSha1Signer());
        try {
          URL serverURLObject = new URL(serverURL);
          URL serverURLSecured = new URL("https", serverURLObject.getHost(), serverURLObject.getPort(), serverURLObject.getFile());
          String stringServURL = serverURLSecured.toString();
          if(!stringServURL.endsWith("/")){
View Full Code Here

Examples of com.google.gdata.client.authn.oauth.GoogleOAuthHelper

    oAuthParameters.setOAuthCallback(requestUrl.toString());

    try {
      OAuthRsaSha1Signer signer = new OAuthRsaSha1Signer(getPrivateKey());
      GoogleOAuthHelper oauthHelper = new GoogleOAuthHelper(signer);

      // Step 1. Request token.
      oauthHelper.getUnauthorizedRequestToken(oAuthParameters);

      // Step 3. Return URL user will be redirected to authenticate.
      return oauthHelper.createUserAuthorizationUrl(oAuthParameters);

    } catch (OAuthException e) {
      authServiceError = e.getMessage();
    }
    return "";
View Full Code Here

Examples of com.google.gdata.client.authn.oauth.GoogleOAuthHelper

    OAuthSigner signer = null;

    try {
      // Step 7. Exchange authorized request token for access token.
      signer = new OAuthRsaSha1Signer(getPrivateKey());
      GoogleOAuthHelper oauthHelper = new GoogleOAuthHelper(signer);
      oauthHelper.getOAuthParametersFromCallback(requestQuery, oAuthParameters);

      // Step 8. Upgrade to access token.
      return oauthHelper.getAccessToken(oAuthParameters);
    } catch (OAuthException e) {
      authServiceError = e.getMessage();
    }
    return null;
  }
View Full Code Here

Examples of com.google.gdata.client.authn.oauth.GoogleOAuthHelper

    OAuthSigner signer = null;
    oAuthParameters.setOAuthToken(userToken.getSessionToken());

    try {
      signer = new OAuthRsaSha1Signer(getPrivateKey());
      GoogleOAuthHelper oauthHelper = new GoogleOAuthHelper(signer);
      oauthHelper.revokeToken(oAuthParameters);
    } catch (OAuthException e) {
        authServiceError = e.getMessage();
    }
  }
View Full Code Here

Examples of com.google.gdata.client.authn.oauth.GoogleOAuthHelper

          TwoLeggedOAuthHelper twoLeggedOAuthHelper
              = new TwoLeggedOAuthHelper(signer, parameters);
          return twoLeggedOAuthHelper.getAuthorizationHeader(requestUrl.toString(),
              requestMethod);
        } else {
          GoogleOAuthHelper oauthHelper = new GoogleOAuthHelper(signer);
          return oauthHelper.getAuthorizationHeader(requestUrl.toString(),
            requestMethod, parameters);
        }
      } catch (OAuthException e) {
        throw new RuntimeException(e);
      }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.