Skip to content

Commit dd83726

Browse files
lsiracsamtstern
authored andcommitted
[TwitterKit Deprecation] Replace TwitterKit use with Generic IDP (#1714)
1 parent d78e72b commit dd83726

File tree

17 files changed

+39
-277
lines changed

17 files changed

+39
-277
lines changed

app/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ dependencies {
4646
// Needed to override Facebook
4747
implementation(Config.Libs.Androidx.cardView)
4848
implementation(Config.Libs.Androidx.customTabs)
49-
implementation(Config.Libs.Provider.twitter) { isTransitive = true }
5049

5150
implementation(Config.Libs.Misc.glide)
5251
annotationProcessor(Config.Libs.Misc.glideCompiler)

app/src/main/java/com/firebase/uidemo/auth/AuthUiActivity.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,6 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
149149
});
150150
}
151151

152-
if (ConfigurationUtils.isTwitterMisconfigured(this)) {
153-
mUseTwitterProvider.setChecked(false);
154-
mUseTwitterProvider.setEnabled(false);
155-
mUseTwitterProvider.setText(R.string.twitter_label_missing_config);
156-
}
157-
158152
mUseEmailLinkProvider.setOnCheckedChangeListener(new OnCheckedChangeListener() {
159153
@Override
160154
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
@@ -193,8 +187,7 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
193187
});
194188

195189
if (ConfigurationUtils.isGoogleMisconfigured(this)
196-
|| ConfigurationUtils.isFacebookMisconfigured(this)
197-
|| ConfigurationUtils.isTwitterMisconfigured(this)) {
190+
|| ConfigurationUtils.isFacebookMisconfigured(this)) {
198191
showSnackbar(R.string.configuration_required);
199192
}
200193

@@ -394,10 +387,6 @@ private List<IdpConfig> getSelectedProviders() {
394387
.build());
395388
}
396389

397-
if (mUseTwitterProvider.isChecked()) {
398-
selectedProviders.add(new IdpConfig.TwitterBuilder().build());
399-
}
400-
401390
if (mUseEmailProvider.isChecked()) {
402391
selectedProviders.add(new IdpConfig.EmailBuilder()
403392
.setRequireName(mRequireName.isChecked())
@@ -427,6 +416,10 @@ private List<IdpConfig> getSelectedProviders() {
427416
selectedProviders.add(new IdpConfig.AnonymousBuilder().build());
428417
}
429418

419+
if (mUseTwitterProvider.isChecked()) {
420+
selectedProviders.add(new IdpConfig.TwitterBuilder().build());
421+
}
422+
430423
if (mUseMicrosoftProvider.isChecked()) {
431424
selectedProviders.add(new IdpConfig.MicrosoftBuilder().build());
432425
}

app/src/main/java/com/firebase/uidemo/util/ConfigurationUtils.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,6 @@ public static boolean isFacebookMisconfigured(@NonNull Context context) {
2828
context.getString(R.string.facebook_application_id));
2929
}
3030

31-
public static boolean isTwitterMisconfigured(@NonNull Context context) {
32-
List<String> twitterConfigs = Arrays.asList(
33-
context.getString(R.string.twitter_consumer_key),
34-
context.getString(R.string.twitter_consumer_secret)
35-
);
36-
37-
return twitterConfigs.contains(AuthUI.UNCONFIGURED_CONFIG_VALUE);
38-
}
39-
4031
@NonNull
4132
public static List<AuthUI.IdpConfig> getConfiguredProviders(@NonNull Context context) {
4233
List<AuthUI.IdpConfig> providers = new ArrayList<>();
@@ -49,10 +40,6 @@ public static List<AuthUI.IdpConfig> getConfiguredProviders(@NonNull Context con
4940
providers.add(new AuthUI.IdpConfig.FacebookBuilder().build());
5041
}
5142

52-
if (!isTwitterMisconfigured(context)) {
53-
providers.add(new AuthUI.IdpConfig.TwitterBuilder().build());
54-
}
55-
5643
ActionCodeSettings actionCodeSettings = ActionCodeSettings.newBuilder()
5744
.setAndroidPackageName("com.firebase.uidemo", true, null)
5845
.setHandleCodeInApp(true)
@@ -65,7 +52,7 @@ public static List<AuthUI.IdpConfig> getConfiguredProviders(@NonNull Context con
6552
.setActionCodeSettings(actionCodeSettings)
6653
.build());
6754

68-
55+
providers.add(new AuthUI.IdpConfig.TwitterBuilder().build());
6956
providers.add(new AuthUI.IdpConfig.PhoneBuilder().build());
7057
providers.add(new AuthUI.IdpConfig.MicrosoftBuilder().build());
7158
providers.add(new AuthUI.IdpConfig.YahooBuilder().build());

app/src/main/res/values/config.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
<string name="facebook_application_id" translatable="false">CHANGE-ME</string>
77
<string name="facebook_login_protocol_scheme" translatable="false">fbYOUR_APP_ID</string>
88

9-
<string name="twitter_consumer_key" translatable="false">CHANGE-ME</string>
10-
<string name="twitter_consumer_secret" translatable="false">CHANGE-ME</string>
11-
129
<string name="github_client_id" translatable="false">CHANGE-ME</string>
1310
<string name="github_client_secret" translatable="false">CHANGE-ME</string>
1411
</resources>

app/src/main/res/values/strings.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
<string name="configuration_required">Configuration required - see README.md</string>
7272
<string name="google_label_missing_config">Google configuration missing</string>
7373
<string name="facebook_label_missing_config">Facebook configuration missing</string>
74-
<string name="twitter_label_missing_config">Twitter configuration missing</string>
7574

7675
<string name="sign_in_cancelled">Sign in cancelled</string>
7776
<string name="no_internet_connection">No internet connection</string>

auth/README.md

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,6 @@ dependencies {
7070
// Required only if Facebook login support is required
7171
// Find the latest Facebook SDK releases here: https://goo.gl/Ce5L94
7272
implementation 'com.facebook.android:facebook-login:4.x'
73-
74-
// Required only if Twitter login support is required
75-
// Find the latest Twitter SDK releases here: https://goo.gl/E5wZvQ
76-
implementation("com.twitter.sdk.android:twitter-core:3.x@aar") { transitive = true }
7773
}
7874
```
7975

@@ -121,34 +117,7 @@ the [Facebook developer dashboard](https://developers.facebook.com):
121117
</resources>
122118
```
123119

124-
#### Twitter
125-
126-
If support for Twitter Sign-in is also required, define the resource strings
127-
`twitter_consumer_key` and `twitter_consumer_secret` to match the values of your
128-
Twitter app as reported by the [Twitter application manager](https://apps.twitter.com/).
129-
130-
```xml
131-
<resources>
132-
<string name="twitter_consumer_key" translatable="false">YOUR_CONSUMER_KEY</string>
133-
<string name="twitter_consumer_secret" translatable="false">YOUR_CONSUMER_SECRET</string>
134-
</resources>
135-
```
136-
137-
In addition, you must enable the "Request email addresses from users" permission
138-
in the "Permissions" tab of your Twitter app.
139-
140-
In order to resolve the Twitter SDK, add the following repository to your `build.gradle`:
141-
142-
```groovy
143-
allprojects {
144-
repositories {
145-
// ...
146-
maven { url 'https://maven.fabric.io/public' }
147-
}
148-
}
149-
```
150-
151-
#### Microsoft, Apple, and Yahoo
120+
#### Microsoft, Apple, Twitter and Yahoo
152121

153122
No FirebaseUI configuration is required for these providers.
154123

@@ -176,6 +145,11 @@ selectedProviders.add(microsoftConfig);
176145
Note: unlike other sign-in methods, signing in with these providers involves the use of a
177146
[Custom Chrome Tab](https://developer.chrome.com/multidevice/android/customtabs).
178147

148+
##### Twitter
149+
150+
You must enable the "Request email addresses from users" permission in the "Permissions" tab of your
151+
Twitter app.
152+
179153
#### GitHub
180154

181155
We do not currently support Github as a sign-in method in FirebaseUI on Android. The current

auth/auth-proguard.pro

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
# 3P providers are optional
22
-dontwarn com.facebook.**
3-
-dontwarn com.twitter.**
43
# Keep the class names used to check for availablility
54
-keepnames class com.facebook.login.LoginManager
6-
-keepnames class com.twitter.sdk.android.core.identity.TwitterAuthClient
75

86
# Don't note a bunch of dynamically referenced classes
97
-dontnote com.google.**
108
-dontnote com.facebook.**
11-
-dontnote com.twitter.**
129
-dontnote com.squareup.okhttp.**
1310
-dontnote okhttp3.internal.**
1411

@@ -18,7 +15,7 @@
1815

1916
# Retrofit config
2017
-dontnote retrofit2.Platform
21-
-dontwarn retrofit2.** # Also keeps Twitter at bay as long as they keep using Retrofit
18+
-dontwarn retrofit2.**
2219
-dontwarn okhttp3.**
2320
-dontwarn okio.**
2421
-keepattributes Exceptions

auth/build.gradle.kts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,13 @@ dependencies {
4040
compileOnly(Config.Libs.Provider.facebook)
4141
implementation(Config.Libs.Androidx.legacySupportv4) // Needed to override deps
4242
implementation(Config.Libs.Androidx.cardView) // Needed to override Facebook
43-
compileOnly(Config.Libs.Provider.twitter) { isTransitive = true }
4443

4544
testImplementation(Config.Libs.Test.junit)
4645
testImplementation(Config.Libs.Test.truth)
4746
testImplementation(Config.Libs.Test.mockito)
4847
testImplementation(Config.Libs.Test.core)
4948
testImplementation(Config.Libs.Test.robolectric)
5049
testImplementation(Config.Libs.Provider.facebook)
51-
testImplementation(Config.Libs.Provider.twitter) { isTransitive = true }
5250

5351
debugImplementation(project(":internal:lintchecks"))
5452
}

auth/src/main/java/com/firebase/ui/auth/AuthUI.java

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
import com.facebook.login.LoginManager;
2626
import com.firebase.ui.auth.data.model.FlowParameters;
27-
import com.firebase.ui.auth.data.remote.TwitterSignInHandler;
2827
import com.firebase.ui.auth.ui.idp.AuthMethodPickerActivity;
2928
import com.firebase.ui.auth.util.CredentialUtils;
3029
import com.firebase.ui.auth.util.ExtraConstants;
@@ -61,7 +60,6 @@
6160
import com.google.firebase.auth.PhoneAuthProvider;
6261
import com.google.firebase.auth.TwitterAuthProvider;
6362
import com.google.firebase.auth.UserInfo;
64-
import com.twitter.sdk.android.core.TwitterCore;
6563

6664
import java.lang.annotation.Retention;
6765
import java.lang.annotation.RetentionPolicy;
@@ -139,18 +137,18 @@ public final class AuthUI {
139137
Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
140138
MICROSOFT_PROVIDER,
141139
YAHOO_PROVIDER,
142-
APPLE_PROVIDER
140+
APPLE_PROVIDER,
141+
TwitterAuthProvider.PROVIDER_ID
143142
)));
144143

145144
/**
146-
* The set of social authentication providers supported in Firebase Auth UI.
145+
* The set of social authentication providers supported in Firebase Auth UI using their SDK.
147146
*/
148147
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
149148
public static final Set<String> SOCIAL_PROVIDERS =
150149
Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
151150
GoogleAuthProvider.PROVIDER_ID,
152151
FacebookAuthProvider.PROVIDER_ID,
153-
TwitterAuthProvider.PROVIDER_ID,
154152
GithubAuthProvider.PROVIDER_ID)));
155153

156154
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
@@ -203,6 +201,13 @@ public static AuthUI getInstance() {
203201
*/
204202
@NonNull
205203
public static AuthUI getInstance(@NonNull FirebaseApp app) {
204+
if (ProviderAvailability.IS_TWITTER_AVAILABLE) {
205+
String releaseUrl = "https://github.com/firebase/FirebaseUI-Android/releases/tag/6.2.0";
206+
Log.w(TAG, String.format("Beginning with FirebaseUI 6.2.0 you no longer need to " +
207+
"include the TwitterKit SDK to sign in with Twitter. " +
208+
"Go to %s for more information", releaseUrl));
209+
}
210+
206211
AuthUI authUi;
207212
synchronized (INSTANCES) {
208213
authUi = INSTANCES.get(app);
@@ -455,10 +460,6 @@ private Task<Void> signOutIdps(@NonNull Context context) {
455460
if (ProviderAvailability.IS_FACEBOOK_AVAILABLE) {
456461
LoginManager.getInstance().logOut();
457462
}
458-
if (ProviderAvailability.IS_TWITTER_AVAILABLE) {
459-
TwitterSignInHandler.initializeTwitter();
460-
TwitterCore.getInstance().getSessionManager().clearActiveSession();
461-
}
462463
return GoogleSignIn.getClient(context, GoogleSignInOptions.DEFAULT_SIGN_IN).signOut();
463464
}
464465

@@ -483,7 +484,8 @@ public SignInIntentBuilder createSignInIntentBuilder() {
483484
})
484485

485486
@Retention(RetentionPolicy.SOURCE)
486-
public @interface SupportedProvider {}
487+
public @interface SupportedProvider {
488+
}
487489

488490
/**
489491
* Configuration for an identity provider.
@@ -1068,29 +1070,6 @@ public FacebookBuilder setPermissions(@NonNull List<String> permissions) {
10681070
}
10691071
}
10701072

1071-
/**
1072-
* {@link IdpConfig} builder for the Twitter provider.
1073-
*/
1074-
public static final class TwitterBuilder extends Builder {
1075-
public TwitterBuilder() {
1076-
super(TwitterAuthProvider.PROVIDER_ID);
1077-
if (!ProviderAvailability.IS_TWITTER_AVAILABLE) {
1078-
throw new RuntimeException(
1079-
"Twitter provider cannot be configured " +
1080-
"without dependency. Did you forget to add " +
1081-
"'com.twitter.sdk.android:twitter-core:VERSION' dependency?");
1082-
}
1083-
Preconditions.checkConfigured(getApplicationContext(),
1084-
"Twitter provider unconfigured. Make sure to add your key and secret." +
1085-
" See the docs for more info:" +
1086-
" https://github" +
1087-
".com/firebase/FirebaseUI-Android/blob/master/auth/README" +
1088-
".md#twitter",
1089-
R.string.twitter_consumer_key,
1090-
R.string.twitter_consumer_secret);
1091-
}
1092-
}
1093-
10941073
/**
10951074
* {@link IdpConfig} builder for the GitHub provider.
10961075
*/
@@ -1138,6 +1117,19 @@ public AnonymousBuilder() {
11381117
}
11391118
}
11401119

1120+
/**
1121+
* {@link IdpConfig} builder for the Twitter provider.
1122+
*/
1123+
public static final class TwitterBuilder extends GenericOAuthProviderBuilder {
1124+
private static final String PROVIDER_NAME = "Twitter";
1125+
1126+
public TwitterBuilder() {
1127+
super(TwitterAuthProvider.PROVIDER_ID, PROVIDER_NAME,
1128+
R.layout.fui_idp_button_twitter);
1129+
}
1130+
}
1131+
1132+
11411133
/**
11421134
* {@link IdpConfig} builder for the Apple provider.
11431135
*/

0 commit comments

Comments
 (0)