8
8
*/
9
9
package com .parse .twitter ;
10
10
11
+ import com .parse .internal .signpost .basic .DefaultOAuthConsumer ;
12
+ import com .parse .internal .signpost .basic .DefaultOAuthProvider ;
13
+ import com .parse .internal .signpost .basic .HttpURLConnectionClient ;
11
14
import org .apache .http .client .methods .HttpUriRequest ;
12
15
13
16
import android .app .ProgressDialog ;
14
17
import android .content .Context ;
15
18
import android .net .Uri ;
16
- import android .net .http .AndroidHttpClient ;
17
19
import android .os .AsyncTask ;
18
20
import android .webkit .CookieSyncManager ;
19
21
23
25
import com .parse .internal .signpost .OAuthConsumer ;
24
26
import com .parse .internal .signpost .OAuthProvider ;
25
27
import com .parse .internal .signpost .commonshttp .CommonsHttpOAuthConsumer ;
26
- import com .parse .internal .signpost .commonshttp .CommonsHttpOAuthProvider ;
27
28
import com .parse .internal .signpost .http .HttpParameters ;
28
29
30
+ import java .net .HttpURLConnection ;
31
+
29
32
public class Twitter {
30
33
private static final String USER_AGENT = "Parse Android SDK" ;
31
34
@@ -49,6 +52,8 @@ public class Twitter {
49
52
private String userId ;
50
53
private String screenName ;
51
54
55
+ private final HttpURLConnectionClient httpURLConnectionClient = HttpURLConnectionClient .create ();
56
+
52
57
public Twitter (String consumerKey , String consumerSecret ) {
53
58
this .consumerKey = consumerKey ;
54
59
this .consumerSecret = consumerSecret ;
@@ -114,21 +119,27 @@ public void signRequest(HttpUriRequest request) {
114
119
}
115
120
}
116
121
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
+
117
132
public void authorize (final Context context , final AsyncCallback callback ) {
118
133
if (getConsumerKey () == null || getConsumerKey ().length () == 0 || getConsumerSecret () == null
119
134
|| getConsumerSecret ().length () == 0 ) {
120
135
throw new IllegalStateException (
121
136
"Twitter must be initialized with a consumer key and secret before authorization." );
122
137
}
123
138
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 ());
132
143
133
144
final ProgressDialog progress = new ProgressDialog (context );
134
145
progress .setMessage ("Loading..." );
0 commit comments