Package oauth.signpost

Examples of oauth.signpost.OAuthConsumer


     */
    private static String get(URL url)
        throws IOException, OAuthException
    {
        TwitterPreferences prefs = getPreferences();
        OAuthConsumer consumer = prefs.getConsumer();
        return BBHttpClient.get(url, consumer);
    }
View Full Code Here


     *
     * @return consumer.
     */
    public OAuthConsumer getConsumer()
    {
        OAuthConsumer c = getHttpClientConsumer();

        // Init consumer with tokens if available
        if (getAccessToken() != null && getTokenSecret() != null) {
            c.setTokenWithSecret(getAccessToken(), getTokenSecret());
        }

        return c;
    }
View Full Code Here

    }

    public String getAuthURL()
    {
        OAuthProvider provider = getDefaultProvider();
        OAuthConsumer consumer = getDefaultConsumer();

        String authURL = null;
        try
        {
            authURL = provider.retrieveRequestToken(consumer, OAuth.OUT_OF_BAND);
            pinToken = consumer.getToken();
            pinTokenSecret = consumer.getTokenSecret();
        } catch (OAuthException e)
        {
            // Auth exception
        }
View Full Code Here

    public void acquireAccessTokens(String pin)
        throws OAuthException
    {
        OAuthProvider provider = getDefaultProvider();
        OAuthConsumer consumer = getDefaultConsumer();

        consumer.setTokenWithSecret(pinToken, pinTokenSecret);

        pinToken = null;
        pinTokenSecret = null;

        provider.retrieveAccessToken(consumer, pin);

        setAccessToken(consumer.getToken());
        setTokenSecret(consumer.getTokenSecret());
        setScreenName(provider.getResponseParameters().get("screen_name").first());
    }
View Full Code Here

    String consumerSecret = prop.getProperty("oauth.consumer.secret");
    in.close();
   
    System.setProperty("debug", "true");
   
    OAuthConsumer consumer = new CommonsHttpOAuthConsumer(consumerKey, consumerSecret);

    // Note: we have to add the consumer key in the authorization URL to make it work
    OAuthProvider provider = new CommonsHttpOAuthProvider(REQUEST_TOKEN_URL,
                               ACCESS_TOKEN_URL,
                              AUTHORIZATION_URL + "&client_id=" + consumerKey);
    /*
     *  This has to be done once to get request token
     */
    provider.setOAuth10a(true);
    // for some reason, SignPost does not append oauth_callback so I
    // added it directly into the AUTHORIZATION_URL
    String requestUrl = provider.retrieveRequestToken(consumer, CALLBACK_URL);
    System.out.println("Copy/Paste the following URL in your browser: " + requestUrl);
    System.out.print("Enter your token: ");
    // read authorization code
    Scanner scanner = new Scanner(System.in);
    String authorizationCode = scanner.nextLine().trim();

    provider.retrieveAccessToken(consumer, authorizationCode);
       
    String accessToken = consumer.getToken();
    String tokenSecret = consumer.getTokenSecret();
    System.out.println("Token: " + accessToken + ". Secret: " + tokenSecret);

    // store token and secret somewhere in a database or in a file
    // so that it can be used later
       
    /*
     * To be done whenever you use the Kiva API
     */
    OAuthConsumer newConsumer = new CommonsHttpOAuthConsumer(consumerKey, consumerSecret);
    newConsumer.setTokenWithSecret(accessToken, tokenSecret);
    HttpGet request = new HttpGet(RESOURCE_URL);
    consumer.sign(request);

    HttpClient client = new DefaultHttpClient();
    HttpResponse response = client.execute(request);
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

  @RequestMapping(value = "/upgradeToken")
  public String upgradeToken(HttpServletRequest request) throws NoSuchAlgorithmException, IOException, OAuthMessageSignerException,
      OAuthNotAuthorizedException, OAuthExpectationFailedException,
      OAuthCommunicationException {

    OAuthConsumer consumer = (OAuthConsumer) request.getSession()
        .getAttribute(BODYMEDIA_OAUTH_CONSUMER);
    OAuthProvider provider = (OAuthProvider) request.getSession()
        .getAttribute(BODYMEDIA_OAUTH_PROVIDER);
    String verifier = request.getParameter("oauth_verifier");
    provider.retrieveAccessToken(consumer, verifier);
    Guest guest = AuthHelper.getGuest();

        ApiKey apiKey;
        if (request.getParameter("apiKeyId")!=null) {
            long apiKeyId = Long.valueOf(request.getParameter("apiKeyId"));
            apiKey = guestService.getApiKey(apiKeyId);
        } else
            apiKey = guestService.createApiKey(guest.getId(), connector());

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

        // Store the OAuth server keys used for the token upgrade, which are the ones currently in oauth.properties
        // into ApiKeyAttributes.  The values in oauth.properties may change over time, so we need to preserve
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

  }

  @RequestMapping(value = "/upgradeToken")
  public String upgradeToken(HttpServletRequest request,
      HttpServletResponse response) throws OAuthException, OAuthMessageSignerException, OAuthNotAuthorizedException, OAuthExpectationFailedException, OAuthCommunicationException {
    OAuthConsumer consumer = (OAuthConsumer) request.getSession().getAttribute(FRESHBOOKS_OAUTH_CONSUMER);
    OAuthProvider provider = (OAuthProvider) request.getSession().getAttribute(FRESHBOOKS_OAUTH_PROVIDER);
    String verifier = request.getParameter("oauth_verifier");
    provider.retrieveAccessToken(consumer, verifier);
    Guest guest = AuthHelper.getGuest();

        final Connector connector = Connector.getConnector("freshbooks");
        final ApiKey apiKey = guestService.createApiKey(guest.getId(), connector);

    guestService.setApiKeyAttribute(apiKey, "accessToken", consumer.getToken());
    guestService.setApiKeyAttribute(apiKey, "tokenSecret", consumer.getTokenSecret());

    return "redirect:/app/from/"+connector.getName();
  }
View Full Code Here

TOP

Related Classes of oauth.signpost.OAuthConsumer

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.