//The consumer object was lost because the browser got into foreground, need to instantiate it again with your apps token and secret. consumer = new CommonsHttpOAuthConsumer("xxx", "yyy"); //Set the requestToken and the tokenSecret that you got earlier by calling retrieveRequestToken. consumer.setTokenWithSecret(requestToken, tokenSecret); //The provider object is lost, too, so instantiate it again. provider = new CommonsHttpOAuthProvider("https://api.twitter.com/oauth/request_token", "https://api.twitter.com/oauth/access_token", "https://api.twitter.com/oauth/authorize"); //Now that's really important. Because you don't perform the retrieveRequestToken method at this moment, the OAuth method is not detected automatically (there is no communication with Twitter). So, the default is 1.0 which is wrong because the initial request was performed with 1.0a. provider.setOAuth10a(true); provider.retrieveAccessToken(consumer, verifier);
/** * Construct a new {@link OAuthSecurityProvider} using the given OAUTH key and secret. * * @param key * the OAUTH key * @param secret * the OAUTH secret */ public OAuthSecurityProvider(String key, String secret) { this(new CommonsHttpOAuthConsumer(key, secret)); }
@Override protected OAuthConsumer buildOAuthConsumer( String apiAccessKey, String apiAccessSecret ) { return new CommonsHttpOAuthConsumer( apiAccessKey, apiAccessSecret ); }
@Override protected OAuthConsumer buildOAuthConsumer( String apiAccessKey, String apiAccessSecret ) { return new CommonsHttpOAuthConsumer( apiAccessKey, apiAccessSecret ); }
@Override protected OAuthConsumer buildOAuthConsumer(String apiAccessKey, String apiAccessSecret) { return new CommonsHttpOAuthConsumer(apiAccessKey, apiAccessSecret); }
public OAuthSigner( String consumerKey, String consumerSecret, String accessToken, String secretToken ) { this.oauth = new CommonsHttpOAuthConsumer( consumerKey, consumerSecret ); oauth.setTokenWithSecret( accessToken, secretToken ); }
/** * Set the key/secret pair that will be used to sign Http * requests. * * @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.")); } }
public OAuthSigner( String consumerKey, String consumerSecret, String accessToken, String secretToken ) { this.oauth = new CommonsHttpOAuthConsumer( consumerKey, consumerSecret ); oauth.setTokenWithSecret( accessToken, secretToken ); }
//Generate a new oAuthConsumer object commonsHttpOAuthConsumer = new CommonsHttpOAuthConsumer( "Consumer Key", "Consumer Secret Key"); //Generate a new oAuthProvider object commonsHttpOAuthProvider = new CommonsHttpOAuthProvider( "https://www.tumblr.com/oauth/request_token", "https://www.tumblr.com/oauth/access_token", "https://www.tumblr.com/oauth/authorize"); //Retrieve the URL to which the user must be sent in order to authorize the consumer return commonsHttpOAuthProvider.retrieveRequestToken( commonsHttpOAuthConsumer, "Callback URL as registered with Tumblr" );
String access_secret= "xzy"; OAuthConsumer consumer = new CommonsHttpOAuthConsumer(consumer_key, consumer_secret); consumer.setTokenWithSecret(access_token, access_secret);
private void buildConsumer() { if (consumer_key != null && consumer_secret != null && access_token != null && token_secret != null) { consumer = new CommonsHttpOAuthConsumer(consumer_key, consumer_secret); consumer.setMessageSigner(new HmacSha1MessageSigner()); consumer.setTokenWithSecret(access_token, token_secret); } }
@Override public HttpRequest sign(HttpRequest request, String key, String secret) throws LtiSigningException { CommonsHttpOAuthConsumer signer = new CommonsHttpOAuthConsumer(key, secret); try { String body = getRequestBody(request); String bodyHash = new String(Base64.encodeBase64(md.digest(body.getBytes()))); HttpParameters params = new HttpParameters(); params.put("oauth_body_hash", URLEncoder.encode(bodyHash, "UTF-8")); signer.setAdditionalParameters(params); signer.sign(request); } catch (OAuthMessageSignerException|OAuthExpectationFailedException|OAuthCommunicationException|IOException e) { throw new LtiSigningException("Exception encountered while singing Lti request...", e); } return request; }
public static OAuthConsumer initConsumer(String consumerKey, String consumerSecret) { OAuthConsumer consumer = new CommonsHttpOAuthConsumer(consumerKey, consumerSecret); consumer.setMessageSigner(new PlainTextMessageSigner()); consumer.setTokenWithSecret("", ""); return consumer; }
public static HttpPost buildReplaceResult(String url, String key, String secret, String sourcedid, String score, String resultData, Boolean isUrl, String messageId) throws IOException, OAuthException, GeneralSecurityException { String dataXml = ""; if (resultData != null) { String format = isUrl ? resultDataUrl : resultDataText; dataXml = String.format(format, StringEscapeUtils.escapeXml(resultData)); } String messageIdentifier = StringUtils.isBlank(messageId) ? String.valueOf(new Date().getTime()) : messageId; String xml = String.format(ReplaceResultMessageTemplate, StringEscapeUtils.escapeXml(messageIdentifier), StringEscapeUtils.escapeXml(sourcedid), StringEscapeUtils.escapeXml(score), dataXml); HttpParameters parameters = new HttpParameters(); String hash = getBodyHash(xml); parameters.put("oauth_body_hash", URLEncoder.encode(hash, "UTF-8")); CommonsHttpOAuthConsumer signer = new CommonsHttpOAuthConsumer(key, secret); HttpPost request = new HttpPost(url); request.setHeader("Content-Type", "application/xml"); request.setEntity(new StringEntity(xml, "UTF-8")); signer.setAdditionalParameters(parameters); signer.sign(request); return request; }
OAuthConsumer consumer = new CommonsHttpOAuthConsumer(consumerKey,consumerSecret);
@Override public URI getLocationURI(HttpResponse response, HttpContext context) throws ProtocolException { String urlString = response.getFirstHeader("Location").getValue(); URI uri; try { uri = new URI(urlString); } catch (URISyntaxException e) { 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) { throw new ProtocolException("Could not sign request!"); } } // Apache puts original headers back on the request, so we need to pass this along to the RequestInterceptor to be re-added. context.setAttribute("AuthHeader", request.getFirstHeader("Authorization")); return uri; }
try OAuthConsumer returnedConsumer = new CommonsHttpOAuthConsumer( consumer.getConsumerKey(), consumer.getConsumerSecret()); returnedConsumer.setMessageSigner(new PlainTextMessageSigner());
@Override public OAuthConsumer getConsumer() { OAuthConsumer consumer = new CommonsHttpOAuthConsumer(data.oauthClientKeys.getConsumerKey(), data.oauthClientKeys.getConsumerSecret()); if (getCredentialsPresent()) { consumer.setTokenWithSecret(getUserToken(), getUserSecret()); } return consumer; }
httpOauthConsumer = new CommonsHttpOAuthConsumer(consumerKey, consumerSecret); httpOauthprovider = new DefaultOAuthProvider(
consumer = new CommonsHttpOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET); provider = new CommonsHttpOAuthProvider(REQUEST_TOKEN_URL, ACCESS_TOKEN_URL, AUTHORIZE_WEBSITE_URL); if(getIsAuthorized() == 0) {