Skip to content

Commit d340365

Browse files
samtsternGerrit Code Review
authored andcommitted
Merge "Merge branch 'version-2.0.0-dev' into phone-auth" into phone-auth
2 parents 7e13be7 + 696aa44 commit d340365

File tree

19 files changed

+49
-224
lines changed

19 files changed

+49
-224
lines changed

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

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@
5353
import butterknife.OnClick;
5454

5555
public class SignedInActivity extends AppCompatActivity {
56-
private static final String EXTRA_SIGNED_IN_CONFIG = "extra_signed_in_config";
5756

58-
private static final int RC_REAUTH = 100;
57+
private static final String EXTRA_SIGNED_IN_CONFIG = "extra_signed_in_config";
5958

6059
@BindView(android.R.id.content)
6160
View mRootView;
@@ -117,22 +116,6 @@ public void onComplete(@NonNull Task<Void> task) {
117116
});
118117
}
119118

120-
@OnClick(R.id.reauthenticate)
121-
public void reauthenticate() {
122-
Intent reauthIntent = AuthUI.getInstance()
123-
.createReauthIntentBuilder()
124-
.setAvailableProviders(mSignedInConfig.providerInfo)
125-
.setIsSmartLockEnabled(mSignedInConfig.isCredentialSelectorEnabled,
126-
mSignedInConfig.isHintSelectorEnabled)
127-
.setLogo(mSignedInConfig.logo)
128-
.setTheme(mSignedInConfig.theme)
129-
.setTosUrl(mSignedInConfig.tosUrl)
130-
.setReauthReason(getString(R.string.reauthentication_reason))
131-
.build();
132-
133-
startActivityForResult(reauthIntent, RC_REAUTH);
134-
}
135-
136119
@OnClick(R.id.delete_account)
137120
public void deleteAccountClicked() {
138121

@@ -310,14 +293,4 @@ public static Intent createIntent(
310293
return startIntent.setClass(context, SignedInActivity.class)
311294
.putExtra(EXTRA_SIGNED_IN_CONFIG, signedInConfig);
312295
}
313-
314-
@Override
315-
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
316-
super.onActivityResult(requestCode, resultCode, data);
317-
if (requestCode == RC_REAUTH) {
318-
mIdpResponse = IdpResponse.fromResultIntent(data);
319-
populateIdpToken();
320-
populateProfile();
321-
}
322-
}
323296
}

app/src/main/res/layout/signed_in_layout.xml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,6 @@
4040
android:layout_margin="16dp"
4141
android:text="@string/sign_out"/>
4242

43-
<Button
44-
android:id="@+id/reauthenticate"
45-
style="@style/Widget.AppCompat.Button.Colored"
46-
android:layout_width="wrap_content"
47-
android:layout_height="wrap_content"
48-
android:layout_gravity="center"
49-
android:layout_margin="16dp"
50-
android:text="@string/reauthenticate"/>
51-
5243
<Button
5344
android:id="@+id/delete_account"
5445
android:layout_width="wrap_content"

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@
6767
<string name="choose_image">Choose Image</string>
6868
<string name="accessibility_downloaded_image">Downloaded image</string>
6969
<string name="allow_new_email_acccount">Allow account creation if email does not exist.</string>
70-
<string name="reauthenticate">Reauth</string>
71-
<string name="reauthentication_reason">Reauth was requested from the test app. Please login to continue.</string>
7270

7371
<!-- strings for database demo activities -->
7472
<string name="start_chatting">No messages. Start chatting at the bottom!</string>

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

Lines changed: 15 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import android.support.annotation.DrawableRes;
2323
import android.support.annotation.NonNull;
2424
import android.support.annotation.Nullable;
25+
import android.support.annotation.StringDef;
2526
import android.support.annotation.StyleRes;
2627
import android.support.v4.app.FragmentActivity;
2728

@@ -71,6 +72,14 @@
7172
* for examples on how to get started with FirebaseUI Auth.
7273
*/
7374
public class AuthUI {
75+
@StringDef({
76+
EmailAuthProvider.PROVIDER_ID, EMAIL_PROVIDER,
77+
PhoneAuthProvider.PROVIDER_ID, PHONE_VERIFICATION_PROVIDER,
78+
GoogleAuthProvider.PROVIDER_ID, GOOGLE_PROVIDER,
79+
FacebookAuthProvider.PROVIDER_ID, FACEBOOK_PROVIDER,
80+
TwitterAuthProvider.PROVIDER_ID, TWITTER_PROVIDER,
81+
})
82+
public @interface SupportedProvider {}
7483

7584
/**
7685
* Provider identifier for email and password credentials, for use with
@@ -333,13 +342,6 @@ public SignInIntentBuilder createSignInIntentBuilder() {
333342
return new SignInIntentBuilder();
334343
}
335344

336-
/**
337-
* Starts the reauthentication flow.
338-
*/
339-
public ReauthIntentBuilder createReauthIntentBuilder() {
340-
return new ReauthIntentBuilder();
341-
}
342-
343345
/**
344346
* Configuration for an identity provider.
345347
* <p>
@@ -350,7 +352,7 @@ public static class IdpConfig implements Parcelable {
350352
private final String mProviderId;
351353
private final List<String> mScopes;
352354

353-
private IdpConfig(@NonNull String providerId, List<String> scopes) {
355+
private IdpConfig(@SupportedProvider @NonNull String providerId, List<String> scopes) {
354356
mProviderId = providerId;
355357
mScopes = Collections.unmodifiableList(scopes);
356358
}
@@ -360,6 +362,7 @@ private IdpConfig(Parcel in) {
360362
mScopes = Collections.unmodifiableList(in.createStringArrayList());
361363
}
362364

365+
@SupportedProvider
363366
public String getProviderId() {
364367
return mProviderId;
365368
}
@@ -415,7 +418,7 @@ public String toString() {
415418
}
416419

417420
public static class Builder {
418-
private String mProviderId;
421+
@SupportedProvider private String mProviderId;
419422
private List<String> mScopes = new ArrayList<>();
420423

421424
/**
@@ -425,7 +428,7 @@ public static class Builder {
425428
* AuthUI#GOOGLE_PROVIDER}. See {@link AuthUI#SUPPORTED_PROVIDERS} for
426429
* the complete list of supported Identity providers
427430
*/
428-
public Builder(@NonNull String providerId) {
431+
public Builder(@SupportedProvider @NonNull String providerId) {
429432
if (!SUPPORTED_PROVIDERS.contains(providerId)) {
430433
throw new IllegalArgumentException("Unkown provider: " + providerId);
431434
}
@@ -458,7 +461,7 @@ public IdpConfig build() {
458461
}
459462

460463
/**
461-
* Base builder for both {@link SignInIntentBuilder} and {@link ReauthIntentBuilder}
464+
* Base builder for both {@link SignInIntentBuilder}.
462465
*/
463466
@SuppressWarnings(value = "unchecked")
464467
private abstract class AuthIntentBuilder<T extends AuthIntentBuilder> {
@@ -660,53 +663,6 @@ public Intent build() {
660663
protected abstract FlowParameters getFlowParams();
661664
}
662665

663-
/**
664-
* Builder for the intent to start the reauthentication flow.
665-
*/
666-
public final class ReauthIntentBuilder extends AuthIntentBuilder<ReauthIntentBuilder> {
667-
private String mReauthReason;
668-
669-
private ReauthIntentBuilder() {
670-
super();
671-
}
672-
673-
/**
674-
* Set an explanation for why reauth was requested e.g. "To delete your account you must
675-
* reauthenticate."
676-
*
677-
* @param reauthReason A string explaining why reauthentication was requested.
678-
*/
679-
public ReauthIntentBuilder setReauthReason(String reauthReason) {
680-
mReauthReason = reauthReason;
681-
return this;
682-
}
683-
684-
@Override
685-
public Intent build() {
686-
if (FirebaseAuth.getInstance(mApp).getCurrentUser() == null) {
687-
throw new IllegalStateException("User must be currently logged in to reauthenticate");
688-
}
689-
690-
return super.build();
691-
}
692-
693-
@Override
694-
protected FlowParameters getFlowParams() {
695-
return new FlowParameters(
696-
mApp.getName(),
697-
mProviders,
698-
mTheme,
699-
mLogo,
700-
mTosUrl,
701-
mPrivacyPolicyUrl,
702-
mEnableCredentials,
703-
mEnableHints,
704-
false,
705-
true,
706-
mReauthReason);
707-
}
708-
}
709-
710666
/**
711667
* Builder for the intent to start the user authentication flow.
712668
*/
@@ -738,9 +694,7 @@ protected FlowParameters getFlowParams() {
738694
mPrivacyPolicyUrl,
739695
mEnableCredentials,
740696
mEnableHints,
741-
mAllowNewEmailAccounts,
742-
false,
743-
null);
697+
mAllowNewEmailAccounts);
744698
}
745699
}
746700
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public Intent toIntent() {
8787
* Get the type of provider. e.g. {@link AuthUI#GOOGLE_PROVIDER}
8888
*/
8989
@NonNull
90+
@AuthUI.SupportedProvider
9091
public String getProviderType() {
9192
return mProviderId;
9293
}
@@ -164,7 +165,7 @@ public static class Builder {
164165
private String mToken;
165166
private String mSecret;
166167

167-
public Builder(@NonNull String providerId, @Nullable String email) {
168+
public Builder(@AuthUI.SupportedProvider @NonNull String providerId, @Nullable String email) {
168169
mProviderId = providerId;
169170
mEmail = email;
170171
}

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

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22

33
import android.content.Context;
44
import android.content.DialogInterface;
5-
import android.content.DialogInterface.OnClickListener;
65
import android.content.Intent;
76
import android.net.ConnectivityManager;
87
import android.os.Bundle;
98
import android.support.annotation.RestrictTo;
10-
import android.support.v7.app.AlertDialog;
11-
import android.text.TextUtils;
129
import android.util.Log;
10+
1311
import com.firebase.ui.auth.ui.ActivityHelper;
1412
import com.firebase.ui.auth.ui.ExtraConstants;
1513
import com.firebase.ui.auth.ui.FlowParameters;
@@ -87,41 +85,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
8785

8886
private void start() {
8987
FlowParameters flowParams = mActivityHelper.getFlowParams();
90-
if (flowParams.isReauth) {
91-
showReauthDialog();
92-
} else {
93-
SignInDelegate.delegate(this, flowParams);
94-
}
95-
}
96-
97-
private void showReauthDialog() {
98-
final FlowParameters flowParams = mActivityHelper.getFlowParams();
99-
AlertDialog.Builder builder = new AlertDialog.Builder(this)
100-
.setTitle(R.string.reauth_dialog_title)
101-
.setOnCancelListener(new DialogInterface.OnCancelListener() {
102-
@Override
103-
public void onCancel(DialogInterface dialog) {
104-
finish(ResultCodes.CANCELED, new Intent());
105-
}
106-
})
107-
.setPositiveButton(R.string.sign_in_default, new OnClickListener() {
108-
@Override
109-
public void onClick(DialogInterface dialog, int which) {
110-
SignInDelegate.delegate(KickoffActivity.this, flowParams);
111-
}
112-
})
113-
.setNegativeButton(android.R.string.cancel, new OnClickListener() {
114-
@Override
115-
public void onClick(DialogInterface dialog, int which) {
116-
finish(ResultCodes.CANCELED, new Intent());
117-
}
118-
});
119-
120-
if (!TextUtils.isEmpty(flowParams.reauthReason)) {
121-
builder.setMessage(flowParams.reauthReason);
122-
}
123-
124-
builder.create().show();
88+
SignInDelegate.delegate(this, flowParams);
12589
}
12690

12791
/**

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public String getName(Context context) {
8989
}
9090

9191
@Override
92+
@AuthUI.SupportedProvider
9293
public String getProviderId() {
9394
return FacebookAuthProvider.PROVIDER_ID;
9495
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import android.util.Log;
2727
import android.widget.Toast;
2828

29+
import com.firebase.ui.auth.AuthUI;
2930
import com.firebase.ui.auth.AuthUI.IdpConfig;
3031
import com.firebase.ui.auth.IdpResponse;
3132
import com.firebase.ui.auth.R;
@@ -104,6 +105,7 @@ public String getName(Context context) {
104105
}
105106

106107
@Override
108+
@AuthUI.SupportedProvider
107109
public String getProviderId() {
108110
return GoogleAuthProvider.PROVIDER_ID;
109111
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import android.support.annotation.LayoutRes;
88
import android.util.Log;
99

10+
import com.firebase.ui.auth.AuthUI;
1011
import com.firebase.ui.auth.IdpResponse;
1112
import com.firebase.ui.auth.R;
1213
import com.google.firebase.auth.AuthCredential;
@@ -67,6 +68,7 @@ public String getName(Context context) {
6768
}
6869

6970
@Override
71+
@AuthUI.SupportedProvider
7072
public String getProviderId() {
7173
return TwitterAuthProvider.PROVIDER_ID;
7274
}

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

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ public class FlowParameters implements Parcelable {
5353

5454
public final boolean allowNewEmailAccounts;
5555

56-
@Nullable
57-
public final String reauthReason;
58-
public final boolean isReauth;
59-
6056
public final boolean enableCredentials;
6157
public final boolean enableHints;
6258

@@ -69,9 +65,7 @@ public FlowParameters(
6965
@Nullable String privacyPolicyUrl,
7066
boolean enableCredentials,
7167
boolean enableHints,
72-
boolean allowNewEmailAccounts,
73-
boolean isReauth,
74-
String reauthReason) {
68+
boolean allowNewEmailAccounts) {
7569
this.appName = Preconditions.checkNotNull(appName, "appName cannot be null");
7670
this.providerInfo = Collections.unmodifiableList(
7771
Preconditions.checkNotNull(providerInfo, "providerInfo cannot be null"));
@@ -82,8 +76,6 @@ public FlowParameters(
8276
this.enableCredentials = enableCredentials;
8377
this.enableHints = enableHints;
8478
this.allowNewEmailAccounts = allowNewEmailAccounts;
85-
this.isReauth = isReauth;
86-
this.reauthReason = reauthReason;
8779
}
8880

8981
@Override
@@ -97,8 +89,6 @@ public void writeToParcel(Parcel dest, int flags) {
9789
dest.writeInt(enableCredentials ? 1 : 0);
9890
dest.writeInt(enableHints ? 1 : 0);
9991
dest.writeInt(allowNewEmailAccounts ? 1 : 0);
100-
dest.writeInt(isReauth ? 1 : 0);
101-
dest.writeString(reauthReason);
10292
}
10393

10494
@Override
@@ -118,8 +108,6 @@ public FlowParameters createFromParcel(Parcel in) {
118108
boolean enableCredentials = in.readInt() != 0;
119109
boolean enableHints = in.readInt() != 0;
120110
boolean allowNewEmailAccounts = in.readInt() != 0;
121-
boolean isReauth = in.readInt() != 0;
122-
String reauthReason = in.readString();
123111

124112
return new FlowParameters(
125113
appName,
@@ -130,9 +118,7 @@ public FlowParameters createFromParcel(Parcel in) {
130118
privacyPolicyUrl,
131119
enableCredentials,
132120
enableHints,
133-
allowNewEmailAccounts,
134-
isReauth,
135-
reauthReason);
121+
allowNewEmailAccounts);
136122
}
137123

138124
@Override

0 commit comments

Comments
 (0)