Skip to content

Commit 939485b

Browse files
SUPERCILEXsamtstern
authored andcommitted
Fix potential account linking sign-in failure due to recursive sign-in attempts (#1293)
Signed-off-by: Alex Saveau <[email protected]>
1 parent 957f7af commit 939485b

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@
9090
*/
9191
public final class AuthUI {
9292

93-
private static final String TAG = "AuthUI";
93+
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
94+
public static final String TAG = "AuthUI";
9495

9596
@StringDef({
9697
EmailAuthProvider.PROVIDER_ID,

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ private void populateIdpList(List<IdpConfig> providerConfigs,
117117
for (IdpConfig idpConfig : providerConfigs) {
118118
final ProviderSignInBase<?> provider;
119119
@LayoutRes int buttonLayout;
120-
switch (idpConfig.getProviderId()) {
120+
121+
final String providerId = idpConfig.getProviderId();
122+
switch (providerId) {
121123
case GoogleAuthProvider.PROVIDER_ID:
122124
GoogleSignInHandler google = supplier.get(GoogleSignInHandler.class);
123125
google.init(new GoogleSignInHandler.Params(idpConfig));
@@ -154,7 +156,7 @@ private void populateIdpList(List<IdpConfig> providerConfigs,
154156
buttonLayout = R.layout.fui_provider_button_phone;
155157
break;
156158
default:
157-
throw new IllegalStateException("Unknown provider: " + idpConfig.getProviderId());
159+
throw new IllegalStateException("Unknown provider: " + providerId);
158160
}
159161
mProviders.add(provider);
160162

@@ -175,7 +177,12 @@ private void handleResponse(@NonNull IdpResponse response) {
175177
// We have no idea what provider this error stemmed from so just forward
176178
// this along to the handler.
177179
handler.startSignIn(response);
178-
} else if (AuthUI.SOCIAL_PROVIDERS.contains(response.getProviderType())) {
180+
} else if (AuthUI.SOCIAL_PROVIDERS.contains(providerId)) {
181+
// Don't use the response's provider since it can be different than the one
182+
// that launched the sign-in attempt. Ex: the email flow is started, but
183+
// ends up turning into a Google sign-in because that account already
184+
// existed. In the previous example, an extra sign-in would incorrectly
185+
// started.
179186
handler.startSignIn(response);
180187
} else {
181188
// Email or phone: the credentials should have already been saved so simply

auth/src/main/java/com/firebase/ui/auth/viewmodel/ResourceObserver.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import android.support.annotation.NonNull;
55
import android.support.annotation.RestrictTo;
66
import android.support.annotation.StringRes;
7+
import android.util.Log;
78

9+
import com.firebase.ui.auth.AuthUI;
810
import com.firebase.ui.auth.data.model.Resource;
911
import com.firebase.ui.auth.data.model.State;
1012
import com.firebase.ui.auth.ui.FragmentBase;
@@ -51,7 +53,10 @@ public final void onChanged(Resource<T> resource) {
5153
} else {
5254
unhandled = FlowUtils.unhandled(mFragment, e);
5355
}
54-
if (unhandled) { onFailure(e); }
56+
if (unhandled) {
57+
Log.e(AuthUI.TAG, "A sign-in error occurred.", e);
58+
onFailure(e);
59+
}
5560
}
5661
}
5762

0 commit comments

Comments
 (0)