Skip to content
This repository was archived by the owner on Feb 14, 2020. It is now read-only.

Commit 84b724b

Browse files
committed
Make callback url configurable
1 parent b088f68 commit 84b724b

File tree

3 files changed

+38
-21
lines changed

3 files changed

+38
-21
lines changed

library/src/main/java/com/parse/ParseTwitterUtils.java

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
* Provides a set of utilities for using Parse with Twitter.
2424
*/
2525
public final class ParseTwitterUtils {
26-
/* package */ static final String AUTH_TYPE = "twitter";
26+
private static final String AUTH_TYPE = "twitter";
27+
28+
private static final String CALLBACK_URL = "twittersdk://";
2729

2830
private static final Object lock = new Object();
2931
/* package for tests */ static boolean isInitialized;
@@ -51,20 +53,35 @@ public static Twitter getTwitter() {
5153
/**
5254
* Initializes Twitter for use with Parse. This method must be invoked prior to calling
5355
* {@link #link(ParseUser, Context, SaveCallback)} and {@link #logIn(Context, LogInCallback)}.
54-
*
56+
*
5557
* @param consumerKey
5658
* Your Twitter consumer key.
5759
* @param consumerSecret
5860
* Your Twitter consumer secret.
5961
*/
6062
public static void initialize(String consumerKey, String consumerSecret) {
63+
initialize(consumerKey, consumerSecret, CALLBACK_URL);
64+
}
65+
66+
/**
67+
* Initializes Twitter for use with Parse. This method must be invoked prior to calling
68+
* {@link #link(ParseUser, Context, SaveCallback)} and {@link #logIn(Context, LogInCallback)}.
69+
*
70+
* @param consumerKey
71+
* Your Twitter consumer key.
72+
* @param consumerSecret
73+
* Your Twitter consumer secret.
74+
* @param callbackUrl
75+
* the callback url
76+
*/
77+
public static void initialize(String consumerKey, String consumerSecret, String callbackUrl) {
6178
synchronized (lock) {
6279
if (isInitialized) {
6380
return;
6481
}
6582

6683
if (controller == null) {
67-
Twitter twitter = new Twitter(consumerKey, consumerSecret);
84+
Twitter twitter = new Twitter(consumerKey, consumerSecret, callbackUrl);
6885
controller = new TwitterController(twitter);
6986
} else {
7087
controller.initialize(consumerKey, consumerSecret);
@@ -133,7 +150,7 @@ public static void link(ParseUser user, Context context) {
133150
* Links a ParseUser to a Twitter account, allowing you to use Twitter for authentication, and
134151
* providing access to Twitter data for the user. A dialog will be shown to the user for Twitter
135152
* authentication.
136-
*
153+
*
137154
* @param user
138155
* The user to link to a Twitter account.
139156
* @param context
@@ -190,7 +207,7 @@ public static void link(ParseUser user, String twitterId, String screenName, Str
190207
* Links a ParseUser to a Twitter account, allowing you to use Twitter for authentication, and
191208
* providing access to Twitter data for the user. This method allows you to handle getting the
192209
* auth tokens for your users, rather than delegating to the provided dialog log-in.
193-
*
210+
*
194211
* @param user
195212
* The user to link to a Twitter account.
196213
* @param twitterId
@@ -247,7 +264,7 @@ public static Task<ParseUser> logInInBackground(String twitterId, String screenN
247264
* credentials does not already exist, a new user will be created. This method allows you to
248265
* handle getting the auth tokens for your users, rather than delegating to the provided dialog
249266
* log-in.
250-
*
267+
*
251268
* @param twitterId
252269
* The user's Twitter ID.
253270
* @param screenName
@@ -293,7 +310,7 @@ public Task<ParseUser> then(Task<Map<String, String>> task) throws Exception {
293310
* Logs in a ParseUser using Twitter for authentication. If a user for the given Twitter
294311
* credentials does not already exist, a new user will be created. A dialog will be shown to the
295312
* user for Twitter authentication.
296-
*
313+
*
297314
* @param context
298315
* An Android context from which the login dialog can be launched.
299316
* @param callback

library/src/main/java/com/parse/TwitterController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
private Task<Map<String, String>>.TaskCompletionSource currentTcs;
3333

3434
public TwitterController() {
35-
this(new Twitter("", ""));
35+
this(new Twitter("", "", ""));
3636
}
3737

3838
public TwitterController(Twitter twitter) {

library/src/main/java/com/parse/twitter/Twitter.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@
88
*/
99
package 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;
14-
import org.apache.http.client.methods.HttpUriRequest;
15-
1611
import android.app.ProgressDialog;
1712
import android.content.Context;
1813
import android.net.Uri;
1914
import android.os.AsyncTask;
2015
import android.webkit.CookieSyncManager;
2116

22-
import com.parse.oauth.OAuth1FlowDialog;
23-
import com.parse.oauth.OAuth1FlowException;
24-
import com.parse.oauth.OAuth1FlowDialog.FlowResultHandler;
2517
import com.parse.internal.signpost.OAuthConsumer;
2618
import com.parse.internal.signpost.OAuthProvider;
19+
import com.parse.internal.signpost.basic.DefaultOAuthConsumer;
20+
import com.parse.internal.signpost.basic.DefaultOAuthProvider;
21+
import com.parse.internal.signpost.basic.HttpURLConnectionClient;
2722
import com.parse.internal.signpost.commonshttp.CommonsHttpOAuthConsumer;
2823
import com.parse.internal.signpost.http.HttpParameters;
24+
import com.parse.oauth.OAuth1FlowDialog;
25+
import com.parse.oauth.OAuth1FlowDialog.FlowResultHandler;
26+
import com.parse.oauth.OAuth1FlowException;
27+
28+
import org.apache.http.client.methods.HttpUriRequest;
2929

3030
import java.net.HttpURLConnection;
3131

@@ -40,11 +40,10 @@ public class Twitter {
4040
private static final String USER_ID_PARAM = "user_id";
4141
private static final String SCREEN_NAME_PARAM = "screen_name";
4242

43-
private static final String CALLBACK_URL = "twitter-oauth://complete";
44-
4543
// App configuration for enabling authentication.
4644
private String consumerKey;
4745
private String consumerSecret;
46+
private String callbackUrl;
4847

4948
// User information.
5049
private String authToken;
@@ -54,9 +53,10 @@ public class Twitter {
5453

5554
private final HttpURLConnectionClient httpURLConnectionClient = HttpURLConnectionClient.create();
5655

57-
public Twitter(String consumerKey, String consumerSecret) {
56+
public Twitter(String consumerKey, String consumerSecret, String callbackUrl) {
5857
this.consumerKey = consumerKey;
5958
this.consumerSecret = consumerSecret;
59+
this.callbackUrl = callbackUrl;
6060
}
6161

6262
public String getConsumerKey() {
@@ -155,7 +155,7 @@ protected void onPostExecute(String result) {
155155
return;
156156
}
157157
CookieSyncManager.createInstance(context);
158-
OAuth1FlowDialog dialog = new OAuth1FlowDialog(context, result, CALLBACK_URL,
158+
OAuth1FlowDialog dialog = new OAuth1FlowDialog(context, result, callbackUrl,
159159
"api.twitter", new FlowResultHandler() {
160160

161161
@Override
@@ -237,7 +237,7 @@ protected void onPreExecute() {
237237
@Override
238238
protected String doInBackground(Void... params) {
239239
try {
240-
return provider.retrieveRequestToken(consumer, CALLBACK_URL);
240+
return provider.retrieveRequestToken(consumer, callbackUrl);
241241
} catch (Throwable e) {
242242
error = e;
243243
}

0 commit comments

Comments
 (0)