Package oauth.signpost.basic

Examples of oauth.signpost.basic.DefaultOAuthConsumer


                                        String consumerSecret, String callbackUrl )
        throws BuzzAuthenticationException
    {

        String authUrl = null;
        consumer = new DefaultOAuthConsumer( consumerKey, consumerSecret, method );

        try
        {
            provider = new DefaultOAuthProvider( consumer, GET_REQUEST_TOKEN_URL + "?scope="
                + URLEncoder.encode( scope, "utf-8" ), GET_ACCESS_TOKEN_URL, AUTHORIZE_TOKEN_URL + "?scope="
View Full Code Here


      long then = System.currentTimeMillis();
      URL url = new URL(urlString);
      HttpURLConnection request = (HttpURLConnection) url
          .openConnection();

      OAuthConsumer consumer = new DefaultOAuthConsumer(accessToken,
          tokenSecret);
      consumer.setTokenWithSecret("", "");
      consumer.setMessageSigner(new HmacSha1MessageSigner());
      consumer.setSendEmptyTokens(true);

      // sign the request (consumer is a Signpost DefaultOAuthConsumer)
      try {
        consumer.sign(request);
      } catch (Exception e) {
        throw new RuntimeException("OAuth exception: " + e.getMessage());
      }
      request.connect();
            final int httpResponseCode = request.getResponseCode();
View Full Code Here

        try {
      long then = System.currentTimeMillis();
      URL url = new URL(urlString);
      HttpURLConnection request = (HttpURLConnection) url.openConnection();
     
      OAuthConsumer consumer = new DefaultOAuthConsumer(
          getConsumerKey(apiKey), getConsumerSecret(apiKey));
 
      consumer.setTokenWithSecret(
                    guestService.getApiKeyAttribute(apiKey,"accessToken"),
                    guestService.getApiKeyAttribute(apiKey,"tokenSecret"));

      // sign the request (consumer is a Signpost DefaultOAuthConsumer)
      try {
        consumer.sign(request);
      } catch (Exception e) {
        throw new RuntimeException("OAuth exception: " + e.getMessage());
      }
      request.connect();
            final int httpResponseCode = request.getResponseCode();
View Full Code Here

            URL url = new URL(urlString);
            HttpURLConnection request = (HttpURLConnection) url.openConnection();
            if (method!=null && method.length>0)
                request.setRequestMethod(method[0]);

            OAuthConsumer consumer = new DefaultOAuthConsumer(
                    getConsumerKey(apiKey), getConsumerSecret(apiKey));

            consumer.setTokenWithSecret(
                    guestService.getApiKeyAttribute(apiKey,"accessToken"),
                    guestService.getApiKeyAttribute(apiKey,"tokenSecret"));

            // sign the request (consumer is a Signpost DefaultOAuthConsumer)
            try {
                consumer.sign(request);
            } catch (Exception e) {
                throw new RuntimeException("OAuth exception: " + e.getMessage());
            }
            request.connect();
            final int httpResponseCode = request.getResponseCode();
View Full Code Here

    public static OAuthConsumer getDefaultConsumer()
    {
        String consumerKey = ResourceUtils.getString("twitter.consumer_key");
        String consumerSecret = ResourceUtils.getString("twitter.consumer_secret");

        return new DefaultOAuthConsumer(consumerKey, consumerSecret);
    }
View Full Code Here

      oauthCallback += "?guestId=" + request.getParameter("guestId");
        if (request.getParameter("apiKeyId") != null)
            oauthCallback += "?apiKeyId=" + request.getParameter("apiKeyId");

        String apiKey = env.get("bodymediaConsumerKey");
    OAuthConsumer consumer = new DefaultOAuthConsumer(
        apiKey,
        env.get("bodymediaConsumerSecret"));
    HttpParameters additionalParameter = new HttpParameters();
    additionalParameter.put("api_key", apiKey);
    consumer.setAdditionalParameters(additionalParameter);

    HttpClient httpClient = env.getHttpClient();

    OAuthProvider provider = new CommonsHttpOAuthProvider(
        "https://api.bodymedia.com/oauth/request_token?api_key="+apiKey,
        "https://api.bodymedia.com/oauth/access_token?api_key="+apiKey,
        "https://api.bodymedia.com/oauth/authorize?api_key="+apiKey, httpClient);

    request.getSession().setAttribute(BODYMEDIA_OAUTH_CONSUMER, consumer);
    request.getSession().setAttribute(BODYMEDIA_OAUTH_PROVIDER, provider);

        String approvalPageUrl = null;
        try {
            approvalPageUrl = provider.retrieveRequestToken(consumer,
                    oauthCallback);
        } catch (Throwable t) {
            logger.error("Couldn't retrieve BodyMedia request token.");
            t.printStackTrace();
            notificationsService.addNamedNotification(AuthHelper.getGuestId(),
                                                      Notification.Type.ERROR, connector().statusNotificationName(),
                                                      "Oops. There was an error with the BodyMedia API. " +
                                                      "Hang tight, we are working on it.");
            // TODO: Should we record permanent failure since an existing connector won't work again until
            // it is reauthenticated?  We would need to get hold of the apiKey and do:
            //  guestService.setApiKeyStatus(apiKey.getId(), ApiKey.Status.STATUS_PERMANENT_FAILURE, null);

            return "redirect:/app/";
        }
   
    System.out.println("the token secret is: " + consumer.getTokenSecret());
    approvalPageUrl+="&oauth_api=" + apiKey;
    approvalPageUrl = URLDecoder.decode(approvalPageUrl, "UTF-8");

    return "redirect:" + approvalPageUrl;
  }
View Full Code Here

        // in the ApiKeyAttribute table at the time of creation based on the values present in
        // oauth.properties.
        String bodymediaConsumerKey = guestService.getApiKeyAttribute(updateInfo.apiKey, "bodymediaConsumerKey");
        String bodymediaConsumerSecret = guestService.getApiKeyAttribute(updateInfo.apiKey, "bodymediaConsumerSecret");

        OAuthConsumer consumer = new DefaultOAuthConsumer(
                bodymediaConsumerKey,
                bodymediaConsumerSecret);

        String accessToken = guestService.getApiKeyAttribute(updateInfo.apiKey, "accessToken");
        consumer.setTokenWithSecret(accessToken,
                guestService.getApiKeyAttribute(updateInfo.apiKey, "tokenSecret"));
        HttpParameters additionalParameter = new HttpParameters();
        additionalParameter.put("api_key", bodymediaConsumerKey);
        additionalParameter.put("oauth_token",
                                accessToken);
        consumer.setAdditionalParameters(additionalParameter);

        HttpClient httpClient = env.getHttpClient();

        OAuthProvider provider = new CommonsHttpOAuthProvider(
                "https://api.bodymedia.com/oauth/request_token?api_key="+bodymediaConsumerKey,
                "https://api.bodymedia.com/oauth/access_token?api_key="+bodymediaConsumerKey,
                "https://api.bodymedia.com/oauth/authorize?api_key="+bodymediaConsumerKey, httpClient);

        try {
            provider.retrieveAccessToken(consumer, null);

            guestService.setApiKeyAttribute(updateInfo.apiKey,
                                            "accessToken", consumer.getToken());
            guestService.setApiKeyAttribute(updateInfo.apiKey,
                                            "tokenSecret", consumer.getTokenSecret());
            guestService.setApiKeyAttribute(updateInfo.apiKey,
                                            "tokenExpiration", provider.getResponseParameters().get("xoauth_token_expiration_time").first());

            // Record this connector as having status up
            guestService.setApiKeyStatus(updateInfo.apiKey.getId(), ApiKey.Status.STATUS_UP, null, null);
View Full Code Here

    if (request.getParameter("guestId")!=null)
      oauthCallback += "?guestId=" + request.getParameter("guestId");

    String userUrl = "palacehotelsoftware";
   
        OAuthConsumer consumer = new DefaultOAuthConsumer(
                userUrl,
                getConsumerSecret());
        consumer.setMessageSigner(new PlainTextMessageSigner());
               
        OAuthProvider provider = new DefaultOAuthProvider(
            "https://" + userUrl + ".freshbooks.com/oauth/oauth_request.php",
            "https://" + userUrl + ".freshbooks.com/oauth/oauth_access.php",
            "https://" + userUrl + ".freshbooks.com/oauth/oauth_authorize.php");
       
    request.getSession().setAttribute(FRESHBOOKS_OAUTH_CONSUMER, consumer);
    request.getSession().setAttribute(FRESHBOOKS_OAUTH_PROVIDER, provider);
    System.out.println("the token secret is: " + consumer.getTokenSecret());
   
    provider.setOAuth10a(true);
    String approvalPageUrl = provider.retrieveRequestToken(consumer, oauthCallback);
   
    return "redirect:" + approvalPageUrl;
View Full Code Here

    URL url = new URL("https://palacehotelsoftware.freshbooks.com/api/2.1/xml-in");

    HttpURLConnection request = (HttpURLConnection) url
        .openConnection();

    OAuthConsumer consumer = new DefaultOAuthConsumer(
        env.get("freshbooksConsumerKey"),
        env.get("freshbooksConsumerSecret"));
    consumer.setMessageSigner(new PlainTextMessageSigner());
    consumer.setTokenWithSecret(guestService.getApiKeyAttribute(updateInfo.apiKey,"accessToken"),
                                    guestService.getApiKeyAttribute(updateInfo.apiKey,"tokenSecret"));

    consumer.sign(request);
   
    request.setDoOutput(true);
    Writer requestWriter = new OutputStreamWriter(
        request.getOutputStream());
View Full Code Here

      oauthCallback += "?guestId=" + request.getParameter("guestId");

        String consumerKey = getConsumerKey();
    String consumerSecret = getConsumerSecret();
   
    OAuthConsumer consumer = new DefaultOAuthConsumer(
                consumerKey,
                consumerSecret);
       
        OAuthProvider provider = new DefaultOAuthProvider(
            "https://api.linkedin.com/uas/oauth/requestToken",
            "https://api.linkedin.com/uas/oauth/accessToken",
            "https://api.linkedin.com/uas/oauth/authorize");
       
    request.getSession().setAttribute(LINKEDIN_OAUTH_CONSUMER, consumer);
    request.getSession().setAttribute(LINKEDIN_OAUTH_PROVIDER, provider);
    System.out.println("the token secret is: " + consumer.getTokenSecret());
   
    String approvalPageUrl = provider.retrieveRequestToken(consumer, oauthCallback);
   
    return "redirect:" + approvalPageUrl;
  }
View Full Code Here

TOP

Related Classes of oauth.signpost.basic.DefaultOAuthConsumer

Copyright © 2018 www.massapicom. 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.