Skip to content
This repository was archived by the owner on Feb 5, 2025. It is now read-only.

Commit 1d2dd92

Browse files
committed
Merge branch 'develop'
2 parents 8a54fec + 1d26db6 commit 1d2dd92

File tree

6 files changed

+122
-82
lines changed

6 files changed

+122
-82
lines changed

WordPressAuthenticator.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "WordPressAuthenticator"
3-
s.version = "1.8.0-beta.7"
3+
s.version = "1.8.0-beta.9"
44
s.summary = "WordPressAuthenticator implements an easy and elegant way to authenticate your WordPress Apps."
55

66
s.description = <<-DESC

WordPressAuthenticator/Signin/AppleAuthenticator.swift

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import WordPressKit
44

55
#if XCODE11
66

7+
@objc protocol AppleAuthenticatorDelegate {
8+
func showWPComLogin(loginFields: LoginFields)
9+
}
10+
711
class AppleAuthenticator: NSObject {
812

913
// MARK: - Properties
@@ -12,6 +16,7 @@ class AppleAuthenticator: NSObject {
1216
private override init() {}
1317
private var showFromViewController: UIViewController?
1418
private let loginFields = LoginFields()
19+
weak var delegate: AppleAuthenticatorDelegate?
1520

1621
private var authenticationDelegate: WordPressAuthenticatorDelegate {
1722
guard let delegate = WordPressAuthenticator.shared.delegate else {
@@ -52,12 +57,12 @@ private extension AppleAuthenticator {
5257
@available(iOS 13.0, *)
5358
func createWordPressComUser(appleCredentials: ASAuthorizationAppleIDCredential) {
5459
guard let identityToken = appleCredentials.identityToken,
60+
let token = String(data: identityToken, encoding: .utf8),
5561
let email = appleCredentials.email else {
5662
DDLogError("Apple Authenticator: invalid Apple credentials.")
5763
return
5864
}
5965

60-
let token = identityToken.base64EncodedString()
6166
let name = fullName(from: appleCredentials.fullName)
6267

6368
updateLoginFields(email: email, fullName: name, token: token)
@@ -68,14 +73,16 @@ private extension AppleAuthenticator {
6873

6974
let wpcom = WordPressComCredentials(authToken: wpcomToken, isJetpackLogin: false, multifactor: false, siteURL: self?.loginFields.siteAddress ?? "")
7075
let credentials = AuthenticatorCredentials(wpcom: wpcom)
71-
72-
// New Account
76+
77+
// New WP Account
7378
if accountCreated {
7479
self?.authenticationDelegate.createdWordPressComAccount(username: wpcomUsername, authToken: wpcomToken)
7580
self?.signupSuccessful(with: credentials)
7681
return
7782
}
78-
// TODO: handle Existing Account.
83+
84+
// Existing WP Account
85+
self?.logInInstead()
7986

8087
}, failure: { [weak self] error in
8188
self?.signupFailed(with: error)
@@ -105,6 +112,12 @@ private extension AppleAuthenticator {
105112
DDLogError("Apple Authenticator: signup failed. error: \(error)")
106113
}
107114

115+
func logInInstead() {
116+
WordPressAuthenticator.track(.signupSocialToLogin)
117+
WordPressAuthenticator.track(.loginSocialSuccess)
118+
delegate?.showWPComLogin(loginFields: loginFields)
119+
}
120+
108121
// MARK: - Helpers
109122

110123
func fullName(from components: PersonNameComponents?) -> String {

0 commit comments

Comments
 (0)