88 */
99package com .parse .twitter ;
1010
11+ import com .parse .internal .signpost .basic .DefaultOAuthConsumer ;
12+ import com .parse .internal .signpost .basic .DefaultOAuthProvider ;
13+ import com .parse .internal .signpost .basic .HttpURLConnectionClient ;
1114import org .apache .http .client .methods .HttpUriRequest ;
1215
1316import android .app .ProgressDialog ;
1417import android .content .Context ;
1518import android .net .Uri ;
16- import android .net .http .AndroidHttpClient ;
1719import android .os .AsyncTask ;
1820import android .webkit .CookieSyncManager ;
1921
2325import com .parse .internal .signpost .OAuthConsumer ;
2426import com .parse .internal .signpost .OAuthProvider ;
2527import com .parse .internal .signpost .commonshttp .CommonsHttpOAuthConsumer ;
26- import com .parse .internal .signpost .commonshttp .CommonsHttpOAuthProvider ;
2728import com .parse .internal .signpost .http .HttpParameters ;
2829
30+ import java .net .HttpURLConnection ;
31+
2932public class Twitter {
3033 private static final String USER_AGENT = "Parse Android SDK" ;
3134
@@ -49,6 +52,8 @@ public class Twitter {
4952 private String userId ;
5053 private String screenName ;
5154
55+ private final HttpURLConnectionClient httpURLConnectionClient = HttpURLConnectionClient .create ();
56+
5257 public Twitter (String consumerKey , String consumerSecret ) {
5358 this .consumerKey = consumerKey ;
5459 this .consumerSecret = consumerSecret ;
@@ -114,21 +119,27 @@ public void signRequest(HttpUriRequest request) {
114119 }
115120 }
116121
122+ public void signRequest (HttpURLConnection request ) {
123+ OAuthConsumer consumer = new DefaultOAuthConsumer (getConsumerKey (), getConsumerSecret ());
124+ consumer .setTokenWithSecret (getAuthToken (), getAuthTokenSecret ());
125+ try {
126+ consumer .sign (request );
127+ } catch (Exception e ) {
128+ throw new RuntimeException (e );
129+ }
130+ }
131+
117132 public void authorize (final Context context , final AsyncCallback callback ) {
118133 if (getConsumerKey () == null || getConsumerKey ().length () == 0 || getConsumerSecret () == null
119134 || getConsumerSecret ().length () == 0 ) {
120135 throw new IllegalStateException (
121136 "Twitter must be initialized with a consumer key and secret before authorization." );
122137 }
123138
124- final OAuthProvider provider = new CommonsHttpOAuthProvider (
125- REQUEST_TOKEN_URL , ACCESS_TOKEN_URL , AUTHORIZE_URL ,
126- // Use AndroidHttpClient due to a MITM vulnerability with Apache's default
127- // HostnameVerifier through HttpClient.
128- //TODO (grantland): Re-use same HttpClient everywhere. We can't do this now due to packaging.
129- AndroidHttpClient .newInstance (USER_AGENT , context ));
130- final OAuthConsumer consumer = new CommonsHttpOAuthConsumer (getConsumerKey (),
131- getConsumerSecret ());
139+ final OAuthProvider provider = new DefaultOAuthProvider (REQUEST_TOKEN_URL , ACCESS_TOKEN_URL , AUTHORIZE_URL ,
140+ httpURLConnectionClient );
141+ provider .setRequestHeader ("User-Agent" , USER_AGENT );
142+ final OAuthConsumer consumer = new DefaultOAuthConsumer (getConsumerKey (), getConsumerSecret ());
132143
133144 final ProgressDialog progress = new ProgressDialog (context );
134145 progress .setMessage ("Loading..." );
0 commit comments