Package oauth.signpost

Examples of oauth.signpost.OAuthConsumer


    return doRequest(request, tokenHolder, null);
  }

  private byte[] doRequest(HttpRequestBase request, TokenHolder tokenHolder, HttpParameters oauthParams) {
    try {
      OAuthConsumer consumer = tokenHolder.createConsumer();
      consumer.setAdditionalParameters(oauthParams);
      consumer.sign(request);
      HttpResponse response = client.execute(request);
      int statusCode = response.getStatusLine().getStatusCode();
      HttpEntity entity = response.getEntity();
      byte[] content = entity != null ? readBytes(entity.getContent()) : new byte[0];
      switch (statusCode) {
View Full Code Here


    }
   
    public static String getUserInfo(Credentials credentials, Provider provider)
        throws OAuthMessageSignerException, OAuthExpectationFailedException, OAuthCommunicationException, ClientProtocolException, IOException {
       
        OAuthConsumer consumer = OAuthUtilities.getConsumer(credentials, provider);
       
        HttpGet httpRequest = new HttpGet(getUserInfoURL(provider.getHost()));
        httpRequest.getParams().setParameter(CoreProtocolPNames.USER_AGENT, getUserAgent());
       
        // this is required by the Metaweb API to avoid XSS
        httpRequest.setHeader("X-Requested-With", "1");
       
        // sign the request with the oauth library
        consumer.sign(httpRequest);

        // execute the request
        HttpClient httpClient = new DefaultHttpClient();
        HttpResponse httpResponse = httpClient.execute(httpRequest);
       
View Full Code Here

        return EntityUtils.toString(httpResponse.getEntity());
    }
   
    public static String mqlwrite(Credentials credentials, Provider provider, String query)
    throws OAuthMessageSignerException, OAuthExpectationFailedException, OAuthCommunicationException, ClientProtocolException, IOException, JSONException {
        OAuthConsumer consumer = OAuthUtilities.getConsumer(credentials, provider);

        JSONObject envelope = new JSONObject();
        envelope.put("query", new JSONObject(query));
       
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        formparams.add(new BasicNameValuePair("query", envelope.toString()));
        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");

        HttpPost httpRequest = new HttpPost(getMQLWriteURL(provider.getHost()));
        httpRequest.getParams().setParameter(CoreProtocolPNames.USER_AGENT, getUserAgent());
        httpRequest.setEntity(entity);

        // this is required by the Metaweb API to avoid XSS
        httpRequest.setHeader("X-Requested-With", "1");

        // sign the request with the oauth library
        consumer.sign(httpRequest);

        // execute the request
        HttpClient httpClient = new DefaultHttpClient();
        HttpResponse httpResponse = httpClient.execute(httpRequest);
   
View Full Code Here

            if (freeqKey == null) {
                logger.warn("Calculating OAuth signature");
                HttpPost surrogateRequest = new HttpPost(getUserInfoURL(FREEBASE_HOST));
                surrogateRequest.setEntity(entity);
               
                OAuthConsumer consumer = OAuthUtilities.getConsumer(credentials, provider);
   
                // TODO(SM) This method uses a lot of memory and often results in OutOfMemoryErrors.
                // Is there something we can do to generate an oauth signature without consuming so much memory?
                consumer.sign(surrogateRequest);
                   
                Header[] h = surrogateRequest.getHeaders("Authorization");
                if (h.length > 0) {
                    httpRequest.setHeader("X-Freebase-Credentials", h[0].getValue());
                } else {
View Full Code Here

                // to see at what stage of the OAuth dance we are
               
                // get the request token credentials
                Credentials request_credentials = Credentials.getCredentials(request, provider, Credentials.Type.REQUEST);

                OAuthConsumer consumer = OAuthUtilities.getConsumer(request_credentials, provider);
                OAuthProvider pp = provider.getProvider();
               
                if (request_credentials == null) {
                    // no credentials were found, so let's start the dance

                    // get the request token

                    String url = pp.retrieveRequestToken(consumer, callbackURL);
                   
                    request_credentials = new Credentials(consumer.getToken(), consumer.getTokenSecret(), provider);

                    // and set them to that we can retrieve them later in the second part of the dance
                    Credentials.setCredentials(request, response, request_credentials, Credentials.Type.REQUEST, 3600);
                   
                    // now redirect the user to the Authorize URL where she can authenticate against the
                    // service provider and authorize us.
                    // The provider will bounce the user back here for us to continue the dance.
                   
                    response.sendRedirect(url);
                } else {
                    // we are at the second stage of the dance, so we need need to obtain the access credentials now
                   
                    // if we got here, it means that the user performed a valid authentication against the
                    // service provider and authorized us, so now we can request more permanent credentials
                    // to the service provider and save those as well for later use.

                    // this is set only for OAuth 1.0a 
                    String verificationCode = request.getParameter(OAUTH_VERIFIER_PARAM);
                   
                    pp.retrieveAccessToken(consumer, verificationCode);

                    access_credentials = new Credentials(consumer.getToken(), consumer.getTokenSecret(), provider);

                    // no matter the result, we need to remove the request token
                    Credentials.deleteCredentials(request, response, provider, Credentials.Type.REQUEST);
                   
                    Credentials.setCredentials(request, response, access_credentials, Credentials.Type.ACCESS, 30 * 24 * 3600);
 
View Full Code Here

        }
        String[] consumer_info = infos.get(provider.getHost());
        if (consumer_info == null) {
            throw new RuntimeException("Can't find secrets for provider '" + provider.getHost() + "'");
        }
        OAuthConsumer oauthConsumer = provider.createConsumer(consumer_info[0],consumer_info[1]);
        oauthConsumer.setSigningStrategy(new AuthorizationHeaderSigningStrategy(provider.getRealm()));
        return oauthConsumer;
    }
View Full Code Here

        oauthConsumer.setSigningStrategy(new AuthorizationHeaderSigningStrategy(provider.getRealm()));
        return oauthConsumer;
    }

    public static OAuthConsumer getConsumer(Credentials credentials, Provider provider) {
        OAuthConsumer consumer = getConsumer(provider);
        if (credentials != null) {
            consumer.setTokenWithSecret(credentials.getToken(), credentials.getSecret());
        }
        return consumer;
    }
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

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.