Package oauth.signpost.commonshttp

Examples of oauth.signpost.commonshttp.CommonsHttpOAuthConsumer


    abstract public String getRequestTokenServiceURL();
    abstract public String getAccessTokenServiceURL();
    abstract public String getUserAuthorizationURL();
   
    public OAuthConsumer createConsumer(String consumerKey, String consumerSecret) {
        return new CommonsHttpOAuthConsumer(consumerKey, consumerSecret);
    }
View Full Code Here


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

        return new CommonsHttpOAuthConsumer(consumerKey, consumerSecret);
    }
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

    OAuthConsumer setupConsumer(ApiKey apiKey) {
        String api_key = guestService.getApiKeyAttribute(apiKey, "bodymediaConsumerKey");
        String bodymediaConsumerSecret = guestService.getApiKeyAttribute(apiKey, "bodymediaConsumerSecret");

        OAuthConsumer consumer = new CommonsHttpOAuthConsumer(api_key, bodymediaConsumerSecret);

        String accessToken = guestService.getApiKeyAttribute(apiKey, "accessToken");
        String tokenSecret = guestService.getApiKeyAttribute(apiKey, "tokenSecret");

        consumer.setTokenWithSecret(accessToken, tokenSecret);
        return consumer;
    }
View Full Code Here

    OAuthConsumer setupConsumer(ApiKey apiKey) {
    String twitterConsumerKey = guestService.getApiKeyAttribute(apiKey, "twitterConsumerKey");
    String twitterConsumerSecret = guestService.getApiKeyAttribute(apiKey, "twitterConsumerSecret");

        OAuthConsumer consumer = new CommonsHttpOAuthConsumer(
        twitterConsumerKey,
        twitterConsumerSecret);

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

        return consumer;
  }
View Full Code Here

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

        String consumerKey = getConsumerKey();
    String consumerSecret = getConsumerSecret();
   
    OAuthConsumer consumer = new CommonsHttpOAuthConsumer(
                consumerKey,
                consumerSecret);
       
        OAuthProvider provider = new CommonsHttpOAuthProvider(
            "http://www.khanacademy.org/api/auth/request_token",
            "http://www.khanacademy.org/api/auth/access_token",
            "http://www.khanacademy.org/api/auth/authorize");
       
    request.getSession().setAttribute(KHAN_OAUTH_CONSUMER, consumer);
    request.getSession().setAttribute(KHAN_OAUTH_PROVIDER, provider);

    try {
      provider.retrieveRequestToken(consumer, oauthCallback);
    } catch (Throwable e) {
      //TODO: a redirection happens here, and it should be handled
      System.out.println("redirection here");
    }
    System.out.println("the token secret is (musn't be null): " + consumer.getTokenSecret());
   
    return "redirect:" + "/home";
  }
View Full Code Here

     */
    static class OAuthSigner implements HttpRequestInterceptor {
        protected OAuthConsumer oauth;
        public OAuthSigner( String consumerKey, String consumerSecret,
            String accessToken, String secretToken ) {
            this.oauth = new CommonsHttpOAuthConsumer( consumerKey, consumerSecret );
            oauth.setTokenWithSecret( accessToken, secretToken );
        }
View Full Code Here

public class FireEagleMain {

    public static void main(String[] args) throws Exception {

        OAuthConsumer consumer = new CommonsHttpOAuthConsumer("2qnk0OzpuzzU",
                "Ctp1QtFbtSaFhOJbOLMCUPio9c75zIaG");

        OAuthProvider provider = new CommonsHttpOAuthProvider(
                "https://fireeagle.yahooapis.com/oauth/request_token",
                "https://fireeagle.yahooapis.com/oauth/access_token",
                "https://fireeagle.yahoo.net/oauth/authorize");

        System.out.println("Fetching request token from Fire Eagle...");

        // we do not support callbacks, thus pass OOB
        String authUrl = provider.retrieveRequestToken(consumer, "http://www.example.com");

        System.out.println("Request token: " + consumer.getToken());
        System.out.println("Token secret: " + consumer.getTokenSecret());

        System.out.println("Now visit:\n" + authUrl + "\n... and grant this app authorization");
        System.out.println("Enter the verification code and hit ENTER when you're done");

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String code = br.readLine();

        System.out.println("Fetching access token from Fire Eagle...");

        provider.retrieveAccessToken(consumer, code);

        System.out.println("Access token: " + consumer.getToken());
        System.out.println("Token secret: " + consumer.getTokenSecret());

        HttpPost request = new HttpPost("https://fireeagle.yahooapis.com/api/0.1/update");
        StringEntity body = new StringEntity("city=hamburg&label="
                + URLEncoder.encode("Send via Signpost!", "UTF-8"));
        body.setContentType("application/x-www-form-urlencoded");
        request.setEntity(body);

        consumer.sign(request);

        System.out.println("Sending update request to Fire Eagle...");

        HttpClient httpClient = new DefaultHttpClient();
        HttpResponse response = httpClient.execute(request);
View Full Code Here

      throw new ProtocolException("Could not parse redirect uri.");
    }
   
    HttpUriRequest request = OAuthHttpClient.buildRequest(urlString, HttpRequestMethod.GET, response.getEntity().toString());
   
    OAuthConsumer token = new CommonsHttpOAuthConsumer((String) context.getAttribute("consumerKey"),
        (String) context.getAttribute("consumerSecret"));

    synchronized(this) {
      try {
        token.sign(request);
      } catch (OAuthMessageSignerException e) {
        throw new ProtocolException("Could not sign request!");
      } catch (OAuthExpectationFailedException e) {
        throw new ProtocolException("Could not sign request!");
      } catch (OAuthCommunicationException e) {
View Full Code Here

   * @param key the consumer key
   * @param secret the secret key
   */
  public void setToken(String key, String secret) {
    if(key != null && secret != null) {
      token  = new CommonsHttpOAuthConsumer(key, secret);
      if(token == null)
        logger.info(String.format(Locale.US, "Failed to created OAuth token."));
      else
        logger.info(String.format(Locale.US, "Successfully created OAuth token."));
    }
View Full Code Here

TOP

Related Classes of oauth.signpost.commonshttp.CommonsHttpOAuthConsumer

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.