//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);
@Override protected HttpRequest createRequest(String endpointUrl) throws Exception { HttpPost request = new HttpPost(endpointUrl); return new HttpRequestAdapter(request); }
@Override protected OAuthProvider buildProvider(String requestTokenUrl, String accessTokenUrl, String websiteUrl, boolean mockConnection) throws Exception { if (mockConnection) { CommonHttpOAuthProviderMock provider = new CommonHttpOAuthProviderMock(requestTokenUrl, accessTokenUrl, websiteUrl); provider.mockConnection(OAuth.OAUTH_TOKEN + "=" + TOKEN + "&" + OAuth.OAUTH_TOKEN_SECRET + "=" + TOKEN_SECRET); return provider; } return new CommonsHttpOAuthProvider(requestTokenUrl, accessTokenUrl, websiteUrl); } }
@Override protected OAuthConsumer buildOAuthConsumer( String apiAccessKey, String apiAccessSecret ) { return new CommonsHttpOAuthConsumer( apiAccessKey, apiAccessSecret ); }
@Override protected OAuthProvider buildOAuthProvider(String apiBaseUrl) { if (httpClient == null) setDefaultHttpClient(); return new CommonsHttpOAuthProvider( apiBaseUrl + "/security/oauth/request_token", apiBaseUrl + "/security/oauth/access_token", apiBaseUrl + "/security/oauth/confirm_access", httpClient); }
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 protected oauth.signpost.http.HttpResponse sendRequest(HttpRequest request) throws Exception { HttpResponse response = httpClient.execute((HttpUriRequest) request.unwrap()); return new HttpResponseAdapter(response); }
//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" );
/** * 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)); }
public OAuth(ServiceInfo info, boolean use10a) { this.info = info; this.provider = new CommonsHttpOAuthProvider(info.requestTokenURL, info.accessTokenURL, info.authorizationURL); this.provider.setOAuth10a(use10a); }
@Override protected HttpRequest wrap(Object request) { if (!(request instanceof org.apache.http.HttpRequest)) { throw new IllegalArgumentException( "This consumer expects requests of type " + org.apache.http.HttpRequest.class.getCanonicalName()); } return new HttpRequestAdapter((org.apache.http.client.methods.HttpUriRequest) request); }
@Override protected oauth.signpost.http.HttpResponse sendRequest(HttpRequest request) throws Exception { HttpResponse resp = httpClientMock.execute((HttpUriRequest) request.unwrap()); return new HttpResponseAdapter(resp); }
@Override protected OAuthConsumer buildOAuthConsumer( String apiAccessKey, String apiAccessSecret ) { return new CommonsHttpOAuthConsumer( apiAccessKey, apiAccessSecret ); }
public OAuth(ServiceInfo info, boolean use10a) { this.info = info; this.provider = new CommonsHttpOAuthProvider(info.requestTokenURL, info.accessTokenURL, info.authorizationURL); this.provider.setOAuth10a(use10a); }
@Override public void prepareRequest() throws Exception { HttpPost r = new HttpPost(URL); r.setHeader(HEADER_NAME, HEADER_VALUE); StringEntity body = new StringEntity(PAYLOAD); body.setContentType(CONTENT_TYPE); r.setEntity(body); request = new HttpRequestAdapter(r); } }
@Override protected OAuthConsumer buildOAuthConsumer(String apiAccessKey, String apiAccessSecret) { return new CommonsHttpOAuthConsumer(apiAccessKey, apiAccessSecret); }
@Override protected OAuthProvider buildOAuthProvider( String apiBaseUrl ) { if (httpClient==null) setDefaultHttpClient(); return new CommonsHttpOAuthProvider( apiBaseUrl + "/security/oauth/request_token", apiBaseUrl + "/security/oauth/access_token", apiBaseUrl + "/security/oauth/confirm_access", httpClient ); }
@Override protected HttpRequest createRequest(String endpointUrl) throws Exception { HttpPost request = new HttpPost(endpointUrl); return new HttpRequestAdapter(request); }
public OAuthSigner( String consumerKey, String consumerSecret, String accessToken, String secretToken ) { this.oauth = new CommonsHttpOAuthConsumer( consumerKey, consumerSecret ); oauth.setTokenWithSecret( accessToken, secretToken ); }
public OAuthSigner( String consumerKey, String consumerSecret, String accessToken, String secretToken ) { this.oauth = new CommonsHttpOAuthConsumer( consumerKey, consumerSecret ); oauth.setTokenWithSecret( accessToken, secretToken ); }