Skip to content
This repository was archived by the owner on Feb 5, 2025. It is now read-only.
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
2 changes: 1 addition & 1 deletion WordPressAuthenticator.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "WordPressAuthenticator"
s.version = "1.12.0"
s.version = "1.12.1"
s.summary = "WordPressAuthenticator implements an easy and elegant way to authenticate your WordPress Apps."

s.description = <<-DESC
Expand Down
50 changes: 47 additions & 3 deletions WordPressAuthenticator/Signin/LoginEmailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ open class LoginEmailViewController: LoginViewController, NUXKeyboardResponder {

localizeControls()
setupOnePasswordButtonIfNeeded()

alternativeLoginLabel?.isHidden = showLoginOptions
if !showLoginOptions {
addGoogleButton()
Expand Down Expand Up @@ -187,6 +187,9 @@ open class LoginEmailViewController: LoginViewController, NUXKeyboardResponder {

let button = WPStyleGuide.wpcomSignupButton()
stackView.addArrangedSubview(button)

// Tapping the Sign up text link in "Don't have an account? _Sign up_"
// will present the 3 button view for signing up.
button.on(.touchUpInside) { [weak self] (button) in
guard let vc = LoginPrologueSignupMethodViewController.instantiate(from: .login) else {
DDLogError("Failed to navigate to LoginPrologueSignupMethodViewController")
Expand All @@ -199,7 +202,24 @@ open class LoginEmailViewController: LoginViewController, NUXKeyboardResponder {
vc.dismissBlock = self.dismissBlock
vc.transitioningDelegate = self
vc.modalPresentationStyle = .custom
self.navigationController?.pushViewController(vc, animated: true)

// Don't forget to handle the button taps!
vc.emailTapped = { [weak self] in
self?.performSegue(withIdentifier: .showSigninV2, sender: self)
}
vc.googleTapped = { [weak self] in
guard let toVC = SignupGoogleViewController.instantiate(from: .signup) else {
DDLogError("Failed to navigate to SignupGoogleViewController")
return
}

self?.navigationController?.pushViewController(toVC, animated: true)
}
vc.appleTapped = { [weak self] in
self?.appleTapped()
}

self.navigationController?.present(vc, animated: true, completion: nil)
}

stackView.addConstraints([
Expand Down Expand Up @@ -374,7 +394,7 @@ open class LoginEmailViewController: LoginViewController, NUXKeyboardResponder {

loginWithUsernamePassword(immediately: true)
}

/// Configures loginFields to log into wordpress.com and
/// navigates to the selfhosted username/password form. Displays the specified
/// error message when the new view controller appears.
Expand Down Expand Up @@ -452,6 +472,11 @@ open class LoginEmailViewController: LoginViewController, NUXKeyboardResponder {
loginToSelfHostedSite()
}

private func appleTapped() {
AppleAuthenticator.sharedInstance.delegate = self
AppleAuthenticator.sharedInstance.showFrom(viewController: self)
}


@IBAction func handleTextFieldDidChange(_ sender: UITextField) {
switch sender {
Expand Down Expand Up @@ -533,3 +558,22 @@ extension LoginEmailViewController: GIDSignInDelegate {
signInGoogleAccount(signIn, didSignInFor: user, withError: error)
}
}

// MARK: - AppleAuthenticatorDelegate

extension LoginEmailViewController: AppleAuthenticatorDelegate {

func showWPComLogin(loginFields: LoginFields) {
self.loginFields = loginFields
performSegue(withIdentifier: .showWPComLogin, sender: self)
}
Comment on lines +566 to +569
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should say // no-op? Because in this context: coming from Jetpack Remote Install > Sign up > Continue with Apple, it would never call the showWPComLogin() method...right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do believe showWPComLogin is needed. It's nothing to do with Jetpack at this point, it's all about the SIWA flow.

It pertains to this logic in AppleAuthenticator:

guard !existingNonSocialAccount else {

    if existing2faAccount {
        self?.show2FA()
        return
    }

    self?.updateLoginEmail(wpcomUsername)
    self?.logInInstead()
    return
}

Basically, what happens here is if an Apple ID is used where the email has already been used on a WP account, the flow will re-direct to WP login.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohhh. Nice!


func showApple2FA(loginFields: LoginFields) {
self.loginFields = loginFields
signInAppleAccount()
}

func authFailedWithError(message: String) {
displayErrorAlert(message, sourceTag: .loginApple)
}
}