Skip to content

Commit 5b2fc22

Browse files
committed
Merge branch 'version-1.1.0-dev' into email-refactor
2 parents 18d06ae + 202c56e commit 5b2fc22

26 files changed

+150
-178
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,10 @@ private List<IdpConfig> getSelectedProviders() {
280280
selectedProviders.add(new IdpConfig.Builder(AuthUI.EMAIL_PROVIDER).build());
281281
}
282282

283+
if (mUseTwitterProvider.isChecked()) {
284+
selectedProviders.add(new IdpConfig.Builder(AuthUI.TWITTER_PROVIDER).build());
285+
}
286+
283287
if (mUseFacebookProvider.isChecked()) {
284288
selectedProviders.add(
285289
new IdpConfig.Builder(AuthUI.FACEBOOK_PROVIDER)
@@ -294,10 +298,6 @@ private List<IdpConfig> getSelectedProviders() {
294298
.build());
295299
}
296300

297-
if (mUseTwitterProvider.isChecked()) {
298-
selectedProviders.add(new IdpConfig.Builder(AuthUI.TWITTER_PROVIDER).build());
299-
}
300-
301301
return selectedProviders;
302302
}
303303

auth/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ Twitter app as reported by the [Twitter application manager](https://apps.twitte
9191
</resources>
9292
```
9393

94-
In addition, if you are using Smart Lock or require a user's email, you must enable the
95-
"Request email addresses from users" permission in the "Permissions" tab of your app.
94+
In addition, you must enable the "Request email addresses from users" permission
95+
in the "Permissions" tab of your Twitter app.
9696

9797
## Using FirebaseUI for Authentication
9898

auth/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ dependencies {
4444
compile "com.google.android.gms:play-services-auth:$firebase_version"
4545

4646
compile 'com.facebook.android:facebook-android-sdk:4.18.0'
47-
compile("com.twitter.sdk.android:twitter:2.2.0@aar") { transitive = true }
47+
compile("com.twitter.sdk.android:twitter:2.3.0@aar") { transitive = true }
4848

4949
// The following libraries are needed to prevent incompatibilities with the facebook
5050
// library when updating com.android.support libraries:

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

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import android.content.Intent;
1818
import android.os.Parcel;
1919
import android.os.Parcelable;
20+
import android.support.annotation.NonNull;
2021
import android.support.annotation.Nullable;
2122

2223
import com.firebase.ui.auth.ui.ExtraConstants;
@@ -25,39 +26,37 @@
2526
* A container that encapsulates the result of authenticating with an Identity Provider.
2627
*/
2728
public class IdpResponse implements Parcelable {
28-
2929
private final String mProviderId;
30-
@Nullable
3130
private final String mEmail;
3231
private final String mToken;
3332
private final String mSecret;
3433
private final int mErrorCode;
3534

36-
public IdpResponse(int errorCode) {
35+
private IdpResponse(int errorCode) {
3736
this(null, null, null, null, errorCode);
3837
}
3938

40-
public IdpResponse(String providerId, String email) {
41-
this(providerId, email, null, null);
39+
public IdpResponse(@NonNull String providerId, @NonNull String email) {
40+
this(providerId, email, null, null, ResultCodes.OK);
4241
}
4342

44-
public IdpResponse(String providerId, @Nullable String email, @Nullable String token) {
45-
this(providerId, email, token, null);
43+
public IdpResponse(@NonNull String providerId, @NonNull String email, @NonNull String token) {
44+
this(providerId, email, token, null, ResultCodes.OK);
4645
}
4746

4847
public IdpResponse(
49-
String providerId,
50-
@Nullable String email,
51-
@Nullable String token,
52-
@Nullable String secret) {
48+
@NonNull String providerId,
49+
@NonNull String email,
50+
@NonNull String token,
51+
@NonNull String secret) {
5352
this(providerId, email, token, secret, ResultCodes.OK);
5453
}
5554

56-
public IdpResponse(
55+
private IdpResponse(
5756
String providerId,
58-
@Nullable String email,
59-
@Nullable String token,
60-
@Nullable String secret,
57+
String email,
58+
String token,
59+
String secret,
6160
int errorCode) {
6261
mProviderId = providerId;
6362
mEmail = email;
@@ -87,11 +86,17 @@ public IdpResponse[] newArray(int size) {
8786
/**
8887
* Get the type of provider. e.g. {@link AuthUI#GOOGLE_PROVIDER}
8988
*/
90-
@Nullable
9189
public String getProviderType() {
9290
return mProviderId;
9391
}
9492

93+
/**
94+
* Get the email used to sign in.
95+
*/
96+
public String getEmail() {
97+
return mEmail;
98+
}
99+
95100
/**
96101
* Get the token received as a result of logging in with the specified IDP
97102
*/
@@ -108,14 +113,6 @@ public String getIdpSecret() {
108113
return mSecret;
109114
}
110115

111-
/**
112-
* Get the email used to sign in.
113-
*/
114-
@Nullable
115-
public String getEmail() {
116-
return mEmail;
117-
}
118-
119116
/**
120117
* Get the error code for a failed sign in
121118
*/
@@ -157,6 +154,6 @@ public static Intent getIntent(IdpResponse response) {
157154
}
158155

159156
public static Intent getErrorCodeIntent(int errorCode) {
160-
return new Intent().putExtra(ExtraConstants.EXTRA_IDP_RESPONSE, new IdpResponse(errorCode));
157+
return getIntent(new IdpResponse(errorCode));
161158
}
162159
}

auth/src/main/java/com/firebase/ui/auth/provider/FacebookProvider.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,14 @@ public void startLogin(Activity activity) {
108108

109109
@Override
110110
public void setAuthenticationCallback(IdpCallback callback) {
111-
this.mCallbackObject = callback;
111+
mCallbackObject = callback;
112112
}
113113

114114
@Override
115115
public void onActivityResult(int requestCode, int resultCode, Intent data) {
116-
sCallbackManager.onActivityResult(requestCode, resultCode, data);
116+
if (sCallbackManager != null) {
117+
sCallbackManager.onActivityResult(requestCode, resultCode, data);
118+
}
117119
}
118120

119121
@Override

auth/src/main/java/com/firebase/ui/auth/provider/TwitterProvider.java

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import com.twitter.sdk.android.core.TwitterSession;
1919
import com.twitter.sdk.android.core.identity.TwitterAuthClient;
2020

21+
import java.lang.ref.WeakReference;
22+
2123
import io.fabric.sdk.android.Fabric;
2224

2325
public class TwitterProvider extends Callback<TwitterSession> implements IdpProvider {
@@ -46,7 +48,7 @@ public String getProviderId() {
4648

4749
@Override
4850
public void setAuthenticationCallback(IdpCallback callback) {
49-
this.mCallbackObject = callback;
51+
mCallbackObject = callback;
5052
}
5153

5254
@Override
@@ -61,7 +63,7 @@ public void startLogin(Activity activity) {
6163

6264
@Override
6365
public void success(Result<TwitterSession> result) {
64-
mCallbackObject.onSuccess(createIdpResponse(result.data));
66+
mTwitterAuthClient.requestEmail(result.data, new EmailCallback(result.data, mCallbackObject));
6567
}
6668

6769
@Override
@@ -70,21 +72,47 @@ public void failure(TwitterException exception) {
7072
mCallbackObject.onFailure(new Bundle());
7173
}
7274

73-
private IdpResponse createIdpResponse(TwitterSession twitterSession) {
74-
return new IdpResponse(
75-
TwitterAuthProvider.PROVIDER_ID,
76-
null,
77-
twitterSession.getAuthToken().token,
78-
twitterSession.getAuthToken().secret);
79-
}
75+
private static class EmailCallback extends Callback<String> {
76+
private TwitterSession mTwitterSession;
77+
private WeakReference<IdpCallback> mCallbackObject;
78+
79+
public EmailCallback(TwitterSession session, IdpCallback callbackObject) {
80+
mTwitterSession = session;
81+
mCallbackObject = new WeakReference<>(callbackObject);
82+
}
83+
84+
@Override
85+
public void success(Result<String> emailResult) {
86+
onSuccess(createIdpResponse(emailResult.data));
87+
}
8088

89+
@Override
90+
public void failure(TwitterException exception) {
91+
Log.e(TAG, "Failure retrieving Twitter email. " + exception.getMessage());
92+
// If retrieving the email fails, we should still be able to sign in, but Smart Lock
93+
// and account linking won't work.
94+
onSuccess(createIdpResponse(null));
95+
}
96+
97+
private void onSuccess(IdpResponse response) {
98+
if (mCallbackObject != null) {
99+
mCallbackObject.get().onSuccess(response);
100+
}
101+
}
102+
103+
private IdpResponse createIdpResponse(String email) {
104+
return new IdpResponse(
105+
TwitterAuthProvider.PROVIDER_ID,
106+
email,
107+
mTwitterSession.getAuthToken().token,
108+
mTwitterSession.getAuthToken().secret);
109+
}
110+
}
81111

82112
public static AuthCredential createAuthCredential(IdpResponse response) {
83-
if (!response.getProviderType().equalsIgnoreCase(TwitterAuthProvider.PROVIDER_ID)){
113+
if (!response.getProviderType().equalsIgnoreCase(TwitterAuthProvider.PROVIDER_ID)) {
84114
return null;
85115
}
86-
return TwitterAuthProvider.getCredential(
87-
response.getIdpToken(),
88-
response.getIdpSecret());
116+
return TwitterAuthProvider.getCredential(response.getIdpToken(), response.getIdpSecret());
89117
}
90118
}

auth/src/main/java/com/firebase/ui/auth/ui/idp/AuthMethodPickerActivity.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,7 @@ protected void onDestroy() {
197197
}
198198
}
199199

200-
public static Intent createIntent(
201-
Context context,
202-
FlowParameters flowParams) {
200+
public static Intent createIntent(Context context, FlowParameters flowParams) {
203201
return BaseHelper.createBaseIntent(context, AuthMethodPickerActivity.class, flowParams);
204202
}
205203
}

auth/src/main/java/com/firebase/ui/auth/ui/idp/CredentialSignInHandler.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,24 +69,27 @@ public void onComplete(@NonNull Task<AuthResult> task) {
6969
} else {
7070
if (task.getException() instanceof FirebaseAuthUserCollisionException) {
7171
final String email = mResponse.getEmail();
72-
mHelper.getFirebaseAuth()
73-
.fetchProvidersForEmail(email)
74-
.addOnFailureListener(new TaskFailureLogger(
75-
TAG, "Error fetching providers for email"))
76-
.addOnSuccessListener(new StartWelcomeBackFlow(email))
77-
.addOnFailureListener(new OnFailureListener() {
78-
@Override
79-
public void onFailure(@NonNull Exception e) {
80-
// TODO: What to do when signing in with Credential fails
81-
// and we can't continue to Welcome back flow without
82-
// knowing providers?
83-
}
84-
});
72+
if (email != null) {
73+
mHelper.getFirebaseAuth()
74+
.fetchProvidersForEmail(email)
75+
.addOnFailureListener(new TaskFailureLogger(
76+
TAG, "Error fetching providers for email"))
77+
.addOnSuccessListener(new StartWelcomeBackFlow(email))
78+
.addOnFailureListener(new OnFailureListener() {
79+
@Override
80+
public void onFailure(@NonNull Exception e) {
81+
// TODO: What to do when signing in with Credential fails
82+
// and we can't continue to Welcome back flow without
83+
// knowing providers?
84+
}
85+
});
86+
return;
87+
}
8588
} else {
86-
mHelper.dismissDialog();
8789
Log.e(TAG, "Unexpected exception when signing in with credential",
8890
task.getException());
8991
}
92+
mHelper.dismissDialog();
9093
}
9194
}
9295

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<vector
2+
xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:width="22dp"
4+
android:height="22dp"
5+
android:viewportHeight="266.895"
6+
android:viewportWidth="266.893">
7+
<path
8+
android:fillColor="#FFFFFF"
9+
android:pathData="M248.08,262.31c7.85,0 14.22,-6.37 14.22,-14.23V18.81c0,-7.86 -6.37,-14.22 -14.22,-14.22H18.81c-7.86,0 -14.22,6.37 -14.22,14.22v229.27c0,7.86 6.37,14.23 14.22,14.23H248.08z"/>
10+
<path
11+
android:fillColor="#3C5A99"
12+
android:pathData="M182.41,262.31v-99.8h33.5l5.02,-38.9h-38.51V98.78c0,-11.26 3.13,-18.93 19.27,-18.93l20.6,-0.01V45.04c-3.56,-0.47 -15.79,-1.53 -30.01,-1.53c-29.69,0 -50.03,18.13 -50.03,51.41v28.68h-33.58v38.9h33.58v99.8H182.41z"/>
13+
</vector>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<vector
2+
xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:width="24dp"
4+
android:height="24dp"
5+
android:viewportHeight="512.0"
6+
android:viewportWidth="512.0">
7+
<path
8+
android:fillColor="#4285f4"
9+
android:pathData="M482.6,261.4c0,-16.7 -1.5,-32.8 -4.3,-48.3H256v91.3h127c-5.5,29.5 -22.1,54.5 -47.1,71.2v59.2h76.3c44.6,-41.1 70.4,-101.6 70.4,-173.5z"/>
10+
<path
11+
android:fillColor="#34a853"
12+
android:pathData="M256,492c63.7,0 117.1,-21.1 156.2,-57.2l-76.3,-59.2c-21.1,14.2 -48.2,22.5 -79.9,22.5 -61.5,0 -113.5,-41.5 -132.1,-97.3H45.1v61.2c38.8,77.1 118.6,130 210.9,130z"/>
13+
<path
14+
android:fillColor="#fbbc05"
15+
android:pathData="M123.9,300.8c-4.7,-14.2 -7.4,-29.3 -7.4,-44.8s2.7,-30.7 7.4,-44.8V150H45.1C29.1,181.9 20,217.9 20,256c0,38.1 9.1,74.1 25.1,106l78.8,-61.2z"/>
16+
<path
17+
android:fillColor="#ea4335"
18+
android:pathData="M256,113.9c34.7,0 65.8,11.9 90.2,35.3l67.7,-67.7C373,43.4 319.6,20 256,20c-92.3,0 -172.1,52.9 -210.9,130l78.8,61.2c18.6,-55.8 70.6,-97.3 132.1,-97.3z"/>
19+
</vector>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<vector
2+
xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:width="24dp"
4+
android:height="24dp"
5+
android:viewportHeight="24.0"
6+
android:viewportWidth="24.0">
7+
<path
8+
android:fillColor="#FFFFFF"
9+
android:pathData="M20,4L4,4c-1.1,0 -1.99,0.9 -1.99,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,6c0,-1.1 -0.9,-2 -2,-2zM20,8l-8,5 -8,-5L4,6l8,5 8,-5v2z"/>
10+
</vector>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<vector
2+
xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:width="24dp"
4+
android:height="19dp"
5+
android:viewportHeight="244.18703"
6+
android:viewportWidth="300.00006">
7+
<path
8+
android:fillColor="#FFFFFF"
9+
android:pathData="m94.72,243.18c112.46,0 173.96,-93.17 173.96,-173.96 0,-2.65 -0.05,-5.28 -0.17,-7.9 11.94,-8.63 22.31,-19.4 30.5,-31.66 -10.95,4.87 -22.74,8.15 -35.11,9.63 12.62,-7.57 22.31,-19.54 26.89,-33.82 -11.81,7 -24.9,12.09 -38.82,14.84 -11.16,-11.88 -27.04,-19.32 -44.63,-19.32 -33.76,0 -61.14,27.38 -61.14,61.13 0,4.8 0.54,9.46 1.59,13.94 -50.81,-2.56 -95.87,-26.89 -126.03,-63.88 -5.25,9.04 -8.28,19.53 -8.28,30.73 0,21.21 10.79,39.94 27.21,50.89 -10.03,-0.31 -19.45,-3.06 -27.69,-7.65 -0.01,0.26 -0.01,0.51 -0.01,0.78 0,29.61 21.08,54.33 49.05,59.93 -5.14,1.4 -10.54,2.15 -16.12,2.15 -3.93,0 -7.77,-0.39 -11.49,-1.1 7.78,24.29 30.35,41.97 57.12,42.47 -20.93,16.4 -47.29,26.17 -75.94,26.17 -4.93,0 -9.8,-0.28 -14.58,-0.85 27.06,17.34 59.19,27.46 93.72,27.46"/>
10+
</vector>

auth/src/main/res/values/styles.xml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,28 +197,26 @@
197197
</style>
198198

199199
<style name="FirebaseUI.Button.AccountChooser.EmailButton">
200-
<item name="android:drawableLeft">@drawable/ic_email_white_18dp</item>
200+
<item name="android:drawableLeft">@drawable/ic_mail_white_24dp</item>
201201
<item name="android:visibility">gone</item>
202202
<item name="android:background">@drawable/idp_button_background_email</item>
203203
<item name="android:textColor">#ffffff</item>
204204
</style>
205205

206206
<style name="FirebaseUI.Button.AccountChooser.GoogleButton">
207-
<item name="android:drawableLeft">@drawable/logo_googleg_color_18dp</item>
207+
<item name="android:drawableLeft">@drawable/ic_googleg_color_24dp</item>
208208
<item name="android:background">@drawable/idp_button_background_google</item>
209209
<item name="android:textColor">#757575</item>
210210
</style>
211211

212212
<style name="FirebaseUI.Button.AccountChooser.FacebookButton">
213-
<item name="android:drawableLeft">@drawable/com_facebook_button_icon_white</item>
213+
<item name="android:drawableLeft">@drawable/ic_facebook_white_22dp</item>
214214
<item name="android:background">@drawable/idp_button_background_facebook</item>
215215
<item name="android:textColor">@color/com_facebook_button_text_color</item>
216216
</style>
217217

218218
<style name="FirebaseUI.Button.AccountChooser.TwitterButton">
219-
<item name="android:drawableLeft">@drawable/tw__ic_logo_default</item>
220-
<item name="android:paddingLeft">4dp</item>
221-
<item name="android:drawablePadding">8dp</item>
219+
<item name="android:drawableLeft">@drawable/ic_twitter_bird_white_24dp</item>
222220
<item name="android:background">@drawable/idp_button_background_twitter</item>
223221
<item name="android:textColor">@color/tw__solid_white</item>
224222
</style>

auth/src/test/java/com/firebase/ui/auth/testhelpers/FakeAuthResult.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import com.google.firebase.auth.FirebaseUser;
1919

2020
public class FakeAuthResult implements AuthResult {
21-
FirebaseUser mFirebaseUser;
21+
private FirebaseUser mFirebaseUser;
2222

2323
public FakeAuthResult(FirebaseUser firebaseUser) {
2424
mFirebaseUser = firebaseUser;

0 commit comments

Comments
 (0)