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

Commit eb3af32

Browse files
authored
Merge pull request #768 from wordpress-mobile/wcios/site-credential-completion-handler
Site credentials: Always trigger `completionHandler` when login finishes if possible
2 parents fc51b95 + 075d308 commit eb3af32

File tree

4 files changed

+42
-35
lines changed

4 files changed

+42
-35
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ _None._
3030
3131
-->
3232

33-
## Unreleased
33+
## 6.0.1
3434

3535
### Breaking Changes
3636

@@ -42,7 +42,7 @@ _None._
4242

4343
### Bug Fixes
4444

45-
_None._
45+
- Always trigger `completionHandler` if possible when site credential login finishes. [#768]
4646

4747
### Internal Changes
4848

Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ PODS:
2222
- SVProgressHUD (2.2.5)
2323
- SwiftLint (0.49.1)
2424
- UIDeviceIdentifier (2.2.0)
25-
- WordPressAuthenticator (6.0.0):
25+
- WordPressAuthenticator (6.0.1-beta.1):
2626
- GoogleSignIn (~> 6.0.1)
2727
- Gridicons (~> 1.0)
2828
- "NSURL+IDN (= 0.4)"
@@ -94,7 +94,7 @@ SPEC CHECKSUMS:
9494
SVProgressHUD: 1428aafac632c1f86f62aa4243ec12008d7a51d6
9595
SwiftLint: 32ee33ded0636d0905ef6911b2b67bbaeeedafa5
9696
UIDeviceIdentifier: f33af270ba9045ea18b31d9aab88e42a0082ea67
97-
WordPressAuthenticator: b93b797eae278f7cda42693a652329173f1d5423
97+
WordPressAuthenticator: 3b05690984590e0c97e44fec89bd06ab16a2da1f
9898
WordPressKit: d5bff8713aa7c0092ff6e2a58623e46a99fc897c
9999
WordPressShared: 0aa459e5257a77184db87805a998f447443c9706
100100
WordPressUI: 1cf47a3b78154faf69caa18569ee7ece1e510fa0

WordPressAuthenticator.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Pod::Spec.new do |s|
44
s.name = 'WordPressAuthenticator'
5-
s.version = '6.0.0'
5+
s.version = '6.0.1-beta.1'
66

77
s.summary = 'WordPressAuthenticator implements an easy and elegant way to authenticate your WordPress Apps.'
88
s.description = <<-DESC

WordPressAuthenticator/Unified Auth/View Related/Site Address/SiteCredentialsViewController.swift

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,38 @@ private extension SiteCredentialsViewController {
479479
displayError(error as NSError, sourceTag: sourceTag)
480480
}
481481
}
482+
483+
func syncDataOrPresentWPComLogin(with wporgCredentials: WordPressOrgCredentials) {
484+
if configuration.isWPComLoginRequiredForSiteCredentialsLogin {
485+
presentWPComLogin(wporgCredentials: wporgCredentials)
486+
return
487+
}
488+
// Client didn't explicitly ask for WPCOM credentials. (`isWPComLoginRequiredForSiteCredentialsLogin` is false)
489+
// So, sync the available credentials and finish sign in.
490+
//
491+
let credentials = AuthenticatorCredentials(wporg: wporgCredentials)
492+
WordPressAuthenticator.shared.delegate?.sync(credentials: credentials) { [weak self] in
493+
NotificationCenter.default.post(name: Foundation.Notification.Name(rawValue: WordPressAuthenticator.WPSigninDidFinishNotification), object: nil)
494+
self?.showLoginEpilogue(for: credentials)
495+
}
496+
}
497+
498+
func presentWPComLogin(wporgCredentials: WordPressOrgCredentials) {
499+
// Try to get the jetpack email from XML-RPC response dictionary.
500+
//
501+
guard let loginFields = makeLoginFieldsUsing(xmlrpc: wporgCredentials.xmlrpc,
502+
options: wporgCredentials.options) else {
503+
WPAuthenticatorLogError("Unexpected response from .org site credentials sign in using XMLRPC.")
504+
let credentials = AuthenticatorCredentials(wporg: wporgCredentials)
505+
showLoginEpilogue(for: credentials)
506+
return
507+
}
508+
509+
// Present verify email instructions screen. Passing loginFields will prefill the jetpack email in `VerifyEmailViewController`
510+
//
511+
presentVerifyEmail(loginFields: loginFields)
512+
}
513+
482514
// MARK: - Private Constants
483515

484516
/// Rows listed in the order they were created.
@@ -534,38 +566,13 @@ extension SiteCredentialsViewController {
534566
}
535567

536568
func finishedLogin(withUsername username: String, password: String, xmlrpc: String, options: [AnyHashable: Any]) {
537-
guard let delegate = WordPressAuthenticator.shared.delegate else {
538-
fatalError("Error: Where did the delegate go?")
539-
}
540-
541569
let wporg = WordPressOrgCredentials(username: username, password: password, xmlrpc: xmlrpc, options: options)
542-
let credentials = AuthenticatorCredentials(wporg: wporg)
543-
544-
guard configuration.isWPComLoginRequiredForSiteCredentialsLogin else {
545-
// Client didn't explicitly ask for WPCOM credentials. (`isWPComLoginRequiredForSiteCredentialsLogin` is false)
546-
// So, sync the available credentials and finish sign in.
547-
//
548-
delegate.sync(credentials: credentials) { [weak self] in
549-
NotificationCenter.default.post(name: Foundation.Notification.Name(rawValue: WordPressAuthenticator.WPSigninDidFinishNotification), object: nil)
550-
self?.showLoginEpilogue(for: credentials)
551-
}
552-
return
553-
}
554-
555-
// Try to get the jetpack email from XML-RPC response dictionary.
556-
//
557-
guard let loginFields = makeLoginFieldsUsing(xmlrpc: xmlrpc, options: options) else {
558-
if let completionHandler = completionHandler {
559-
return completionHandler(wporg)
560-
}
561-
WPAuthenticatorLogError("Unexpected response from .org site credentials sign in using XMLRPC.")
562-
showLoginEpilogue(for: credentials)
563-
return
570+
/// If `completionHandler` is available, return early with the credentials.
571+
if let completionHandler = completionHandler {
572+
completionHandler(wporg)
573+
} else {
574+
syncDataOrPresentWPComLogin(with: wporg)
564575
}
565-
566-
// Present verify email instructions screen. Passing loginFields will prefill the jetpack email in `VerifyEmailViewController`
567-
//
568-
presentVerifyEmail(loginFields: loginFields)
569576
}
570577

571578
override func displayRemoteError(_ error: Error) {

0 commit comments

Comments
 (0)