Skip to content

Commit

Permalink
Merge pull request #136 from wordpress-mobile/fix/smart-lock-login-wi…
Browse files Browse the repository at this point in the history
…th-2fa

Fix Smart Lock Login with 2FA issue
  • Loading branch information
irfano authored Feb 1, 2024
2 parents 67b6d24 + 37414ad commit baf5eff
Showing 1 changed file with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.wordpress.android.fluxc.store.AccountStore.AuthenticatePayload;
import org.wordpress.android.fluxc.store.AccountStore.AuthenticationErrorType;
import org.wordpress.android.fluxc.store.AccountStore.OnAuthenticationChanged;
import org.wordpress.android.fluxc.store.AccountStore.OnTwoFactorAuthStarted;
import org.wordpress.android.fluxc.store.SiteStore.OnProfileFetched;
import org.wordpress.android.fluxc.store.SiteStore.OnSiteChanged;
import org.wordpress.android.fluxc.store.SiteStore.RefreshSitesXMLRPCPayload;
Expand Down Expand Up @@ -504,13 +505,7 @@ private void handleAuthError(AuthenticationErrorType error, XmlRpcErrorType xmlR
case INVALID_TOKEN:
case AUTHORIZATION_REQUIRED:
case NEEDS_2FA:
if (mIsWpcom) {
if (mLoginListener != null) {
mLoginListener.needs2fa(mRequestedUsername, mRequestedPassword);
}
} else {
showError("2FA not supported for self-hosted sites. Please use an app-password.");
}
handle2fa();
break;
default:
AppLog.e(T.NUX, "Server response: " + errorMessage);
Expand All @@ -521,8 +516,26 @@ private void handleAuthError(AuthenticationErrorType error, XmlRpcErrorType xmlR
}
}

private void handle2fa() {
if (mIsWpcom) {
if (mLoginListener != null) {
mLoginListener.needs2fa(mRequestedUsername, mRequestedPassword);
}
} else {
showError("2FA not supported for self-hosted sites. Please use an app-password.");
}
}

// OnChanged events

@SuppressWarnings("unused")
@Subscribe(threadMode = ThreadMode.MAIN)
public void onTwoFactorAuthStarted(OnTwoFactorAuthStarted event) {
mLoginStarted = false;
handle2fa();
endProgress();
}

@SuppressWarnings("unused")
@Subscribe(threadMode = ThreadMode.MAIN)
public void onAuthenticationChanged(OnAuthenticationChanged event) {
Expand Down

0 comments on commit baf5eff

Please sign in to comment.