Skip to content

Revert reauthentication #734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 1 addition & 27 deletions app/src/main/java/com/firebase/uidemo/auth/SignedInActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@
import butterknife.OnClick;

public class SignedInActivity extends AppCompatActivity {
private static final String EXTRA_SIGNED_IN_CONFIG = "extra_signed_in_config";

private static final int RC_REAUTH = 100;
private static final String EXTRA_SIGNED_IN_CONFIG = "extra_signed_in_config";

@BindView(android.R.id.content)
View mRootView;
Expand Down Expand Up @@ -113,21 +112,6 @@ public void onComplete(@NonNull Task<Void> task) {
});
}

@OnClick(R.id.reauthenticate)
public void reauthenticate() {
Intent reauthIntent = AuthUI.getInstance()
.createReauthIntentBuilder()
.setAvailableProviders(mSignedInConfig.providerInfo)
.setIsSmartLockEnabled(mSignedInConfig.isSmartLockEnabled)
.setLogo(mSignedInConfig.logo)
.setTheme(mSignedInConfig.theme)
.setTosUrl(mSignedInConfig.tosUrl)
.setReauthReason(getString(R.string.reauthentication_reason))
.build();

startActivityForResult(reauthIntent, RC_REAUTH);
}

@OnClick(R.id.delete_account)
public void deleteAccountClicked() {

Expand Down Expand Up @@ -298,14 +282,4 @@ public static Intent createIntent(
return startIntent.setClass(context, SignedInActivity.class)
.putExtra(EXTRA_SIGNED_IN_CONFIG, signedInConfig);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_REAUTH) {
mIdpResponse = IdpResponse.fromResultIntent(data);
populateIdpToken();
populateProfile();
}
}
}
9 changes: 0 additions & 9 deletions app/src/main/res/layout/signed_in_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,6 @@
android:layout_margin="16dp"
android:text="@string/sign_out"/>

<Button
android:id="@+id/reauthenticate"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="16dp"
android:text="@string/reauthenticate"/>

<Button
android:id="@+id/delete_account"
android:layout_width="wrap_content"
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@
<string name="choose_image">Choose Image</string>
<string name="accessibility_downloaded_image">Downloaded image</string>
<string name="allow_new_email_acccount">Allow account creation if email does not exist.</string>
<string name="reauthenticate">Reauth</string>
<string name="reauthentication_reason">Reauth was requested from the test app. Please login to continue.</string>

<!-- strings for database demo activities -->
<string name="start_chatting">No messages. Start chatting at the bottom!</string>
Expand Down
59 changes: 2 additions & 57 deletions auth/src/main/java/com/firebase/ui/auth/AuthUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,6 @@ public SignInIntentBuilder createSignInIntentBuilder() {
return new SignInIntentBuilder();
}

/**
* Starts the reauthentication flow.
*/
public ReauthIntentBuilder createReauthIntentBuilder() {
return new ReauthIntentBuilder();
}

/**
* Configuration for an identity provider.
* <p>
Expand Down Expand Up @@ -441,7 +434,7 @@ public IdpConfig build() {
}

/**
* Base builder for both {@link SignInIntentBuilder} and {@link ReauthIntentBuilder}
* Base builder for both {@link SignInIntentBuilder}.
*/
@SuppressWarnings(value = "unchecked")
private abstract class AuthIntentBuilder<T extends AuthIntentBuilder> {
Expand Down Expand Up @@ -602,52 +595,6 @@ public Intent build() {
protected abstract FlowParameters getFlowParams();
}

/**
* Builder for the intent to start the reauthentication flow.
*/
public final class ReauthIntentBuilder extends AuthIntentBuilder<ReauthIntentBuilder> {
private String mReauthReason;

private ReauthIntentBuilder() {
super();
}

/**
* Set an explanation for why reauth was requested e.g. "To delete your account you must
* reauthenticate."
*
* @param reauthReason A string explaining why reauthentication was requested.
*/
public ReauthIntentBuilder setReauthReason(String reauthReason) {
mReauthReason = reauthReason;
return this;
}

@Override
public Intent build() {
if (FirebaseAuth.getInstance(mApp).getCurrentUser() == null) {
throw new IllegalStateException("User must be currently logged in to reauthenticate");
}

return super.build();
}

@Override
protected FlowParameters getFlowParams() {
return new FlowParameters(
mApp.getName(),
mProviders,
mTheme,
mLogo,
mTosUrl,
mPrivacyPolicyUrl,
mIsSmartLockEnabled,
false,
true,
mReauthReason);
}
}

/**
* Builder for the intent to start the user authentication flow.
*/
Expand Down Expand Up @@ -678,9 +625,7 @@ protected FlowParameters getFlowParams() {
mTosUrl,
mPrivacyPolicyUrl,
mIsSmartLockEnabled,
mAllowNewEmailAccounts,
false,
null);
mAllowNewEmailAccounts);
}
}
}
40 changes: 2 additions & 38 deletions auth/src/main/java/com/firebase/ui/auth/KickoffActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.support.annotation.RestrictTo;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.util.Log;

import com.firebase.ui.auth.ui.ActivityHelper;
import com.firebase.ui.auth.ui.ExtraConstants;
import com.firebase.ui.auth.ui.FlowParameters;
Expand Down Expand Up @@ -87,41 +85,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {

private void start() {
FlowParameters flowParams = mActivityHelper.getFlowParams();
if (flowParams.isReauth) {
showReauthDialog();
} else {
SignInDelegate.delegate(this, flowParams);
}
}

private void showReauthDialog() {
final FlowParameters flowParams = mActivityHelper.getFlowParams();
AlertDialog.Builder builder = new AlertDialog.Builder(this)
.setTitle(R.string.reauth_dialog_title)
.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
finish(ResultCodes.CANCELED, new Intent());
}
})
.setPositiveButton(R.string.sign_in_default, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SignInDelegate.delegate(KickoffActivity.this, flowParams);
}
})
.setNegativeButton(android.R.string.cancel, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish(ResultCodes.CANCELED, new Intent());
}
});

if (!TextUtils.isEmpty(flowParams.reauthReason)) {
builder.setMessage(flowParams.reauthReason);
}

builder.create().show();
SignInDelegate.delegate(this, flowParams);
}

/**
Expand Down
16 changes: 2 additions & 14 deletions auth/src/main/java/com/firebase/ui/auth/ui/FlowParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ public class FlowParameters implements Parcelable {

public final boolean allowNewEmailAccounts;

@Nullable
public final String reauthReason;
public final boolean isReauth;

public FlowParameters(
@NonNull String appName,
@NonNull List<IdpConfig> providerInfo,
Expand All @@ -67,9 +63,7 @@ public FlowParameters(
@Nullable String termsOfServiceUrl,
@Nullable String privacyPolicyUrl,
boolean smartLockEnabled,
boolean allowNewEmailAccounts,
boolean isReauth,
String reauthReason) {
boolean allowNewEmailAccounts) {
this.appName = Preconditions.checkNotNull(appName, "appName cannot be null");
this.providerInfo = Collections.unmodifiableList(
Preconditions.checkNotNull(providerInfo, "providerInfo cannot be null"));
Expand All @@ -79,8 +73,6 @@ public FlowParameters(
this.privacyPolicyUrl = privacyPolicyUrl;
this.smartLockEnabled = smartLockEnabled;
this.allowNewEmailAccounts = allowNewEmailAccounts;
this.isReauth = isReauth;
this.reauthReason = reauthReason;
}

@Override
Expand All @@ -93,8 +85,6 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeString(privacyPolicyUrl);
dest.writeInt(smartLockEnabled ? 1 : 0);
dest.writeInt(allowNewEmailAccounts ? 1 : 0);
dest.writeInt(isReauth ? 1 : 0);
dest.writeString(reauthReason);
}

@Override
Expand Down Expand Up @@ -124,9 +114,7 @@ public FlowParameters createFromParcel(Parcel in) {
termsOfServiceUrl,
privacyPolicyUrl,
smartLockEnabled,
allowNewEmailAccounts,
isReauth,
reauthReason);
allowNewEmailAccounts);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,9 @@ protected void onCreate(Bundle savedInstanceState) {
ImeHelper.setImeOnDoneListener(mPasswordField, this);

// Create welcome back text with email bolded.
String bodyText;
String bodyText = getString(R.string.welcome_back_password_prompt_body, mEmail);
FlowParameters flowParameters = mActivityHelper.getFlowParams();
if (flowParameters.isReauth) {
welcomeBackHeader.setText(getString(R.string.welcome_back_email_header_reauth));
bodyText = getString(R.string.reauth_welcome_back_password_prompt_body, mEmail);
} else {
bodyText = getString(R.string.welcome_back_password_prompt_body, mEmail);
}

SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(bodyText);
int emailStart = bodyText.indexOf(mEmail);
spannableStringBuilder.setSpan(new StyleSpan(Typeface.BOLD),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ protected void onCreate(Bundle savedInstanceState) {
// Get email from intent (can be null)
String email = getIntent().getExtras().getString(ExtraConstants.EXTRA_EMAIL);

if (mActivityHelper.getFlowParams().isReauth) {
email = mActivityHelper.getCurrentUser().getEmail();
}

// Start with check email
CheckEmailFragment fragment = CheckEmailFragment.newInstance(
mActivityHelper.getFlowParams(), email);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,6 @@ public void onCreate(Bundle savedInstance) {
}

FlowParameters flowParams = mHelper.getFlowParams();
if (flowParams.isReauth) {
// if it's a reauth and it's not an email account, skip Smart Lock.
List<String> providers = mHelper.getCurrentUser().getProviders();
if (providers == null || providers.size() > 0) {
// this is a non-email user, skip Smart Lock
startAuthMethodChoice();
return;
}
}
if (flowParams.smartLockEnabled) {
mHelper.showLoadingDialog(R.string.progress_dialog_loading);

Expand Down Expand Up @@ -248,29 +239,8 @@ private void startAuthMethodChoice() {
providerIdToConfig.put(providerConfig.getProviderId(), providerConfig);
}

List<IdpConfig> visibleProviders = new ArrayList<>();
if (flowParams.isReauth) {
// For reauth flow we only want to show the IDPs which the user has associated with
// their account.
List<String> providerIds = mHelper.getCurrentUser().getProviders();
if (providerIds.size() == 0) {
// zero providers indicates that it is an email account
visibleProviders.add(new IdpConfig.Builder(AuthUI.EMAIL_PROVIDER).build());
} else {
for (String providerId : providerIds) {
IdpConfig idpConfig = providerIdToConfig.get(providerId);
if (idpConfig == null) {
Log.e(TAG, "User has provider " + providerId + " associated with their "
+ "account, but only the following IDPs have been configured: "
+ TextUtils.join(", ", providerIdToConfig.keySet()));
} else {
visibleProviders.add(idpConfig);
}
}
}
} else {
visibleProviders = idpConfigs;
}
List<IdpConfig> visibleProviders = idpConfigs;

// If the only provider is Email, immediately launch the email flow. Otherwise, launch
// the auth method picker screen.
if (visibleProviders.size() == 1) {
Expand All @@ -279,10 +249,8 @@ private void startAuthMethodChoice() {
RegisterEmailActivity.createIntent(getContext(), flowParams),
RC_EMAIL_FLOW);
} else {
String email = flowParams.isReauth ? mHelper.getCurrentUser().getEmail() : null;
redirectToIdpSignIn(email,
providerIdToAccountType(visibleProviders.get(0)
.getProviderId()));
redirectToIdpSignIn(null, providerIdToAccountType(
visibleProviders.get(0).getProviderId()));
}
} else {
startActivityForResult(
Expand Down
8 changes: 0 additions & 8 deletions auth/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
<string name="sign_in_default">Sign in</string>
<string name="general_error">An error has occurred.</string>

<!-- Reauth Dialog -->
<string name="reauth_dialog_title">This action requires you to sign in before continuing.</string>

<!-- Provider -->
<string name="idp_name_google">Google</string>
<string name="idp_name_facebook">Facebook</string>
Expand Down Expand Up @@ -55,7 +52,6 @@
<string name="title_welcome_back_password_prompt">@string/sign_in_default</string>
<string name="welcome_back_idp_header">You already have an account</string>
<string name="welcome_back_email_header">Welcome back!</string>
<string name="welcome_back_email_header_reauth">Reauthentication required</string>
<string name="welcome_back_idp_prompt">
You\'ve already used <xliff:g id="email_addr" example="[email protected]">%1$s</xliff:g>.
Sign in with <xliff:g id="provider_name" example="Google">%2$s</xliff:g> to continue.
Expand All @@ -64,10 +60,6 @@
You\'ve already used <xliff:g id="email_addr" example="[email protected]">%1$s</xliff:g>
to sign in. Enter your password for that account.
</string>
<string name="reauth_welcome_back_password_prompt_body">
You must reauthenticate to continue. Please enter the password for the account with email
<xliff:g id="email_addr" example="[email protected]">%1$s</xliff:g>.
</string>
<string name="progress_dialog_signing_in">Signing in…</string>
<string name="trouble_signing_in">Trouble signing in?</string>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ public static FlowParameters getFlowParameters(List<String> providerIds) {
null /* tosUrl */,
null /* privacyPolicyUrl */,
true /* smartLockEnabled */,
true /* allowNewEmailAccounts */,
false /* isReauth */,
null /* reauthReason */);
true /* allowNewEmailAccounts */);
}

public static void verifySmartLockSave(String providerId, String email, String password) {
Expand Down