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

Commit a52bc06

Browse files
authored
Merge pull request #692 from wordpress-mobile/wcios/store-creation-login-flow
Allow the host app to pass a custom source identifier to the login flow
2 parents d443c19 + bdafedd commit a52bc06

File tree

9 files changed

+37
-10
lines changed

9 files changed

+37
-10
lines changed

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 = '3.3.0-beta.1'
5+
s.version = '3.3.0-beta.2'
66

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

WordPressAuthenticator/Authenticator/WordPressAuthenticator.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ import WordPressKit
1919
///
2020
private var appleIDCredentialObserver: NSObjectProtocol?
2121

22+
/// Optional sign in source that could be from the login prologue or the host app to track the entry point
23+
/// for customizations in the epilogue handling.
24+
var signInSource: SignInSource?
25+
2226
/// Shared Instance.
2327
///
2428
@objc public static var shared: WordPressAuthenticator {

WordPressAuthenticator/Authenticator/WordPressAuthenticatorDelegateProtocol.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@ public protocol WordPressAuthenticatorDelegate: AnyObject {
5454

5555
/// Presents the Login Epilogue, in the specified NavigationController.
5656
///
57-
func presentLoginEpilogue(in navigationController: UINavigationController, for credentials: AuthenticatorCredentials, onDismiss: @escaping () -> Void)
57+
/// - Parameters:
58+
/// - navigationController: navigation stack for any epilogue views to be shown on.
59+
/// - credentials: WPCOM or WPORG credentials.
60+
/// - source: an optional identifier of the login flow, can be from the login prologue or provided by the host app.
61+
/// - onDismiss: called when the auth flow is dismissed.
62+
func presentLoginEpilogue(in navigationController: UINavigationController, for credentials: AuthenticatorCredentials, source: SignInSource?, onDismiss: @escaping () -> Void)
5863

5964
/// Presents the Login Epilogue, in the specified NavigationController.
6065
///

WordPressAuthenticator/Navigation/NavigateToEnterAccount.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ import Foundation
33
/// Navigates to the unified "Continue with WordPress.com" flow.
44
///
55
public struct NavigateToEnterAccount: NavigationCommand {
6-
public init() {}
6+
private let signInSource: SignInSource
7+
8+
public init(signInSource: SignInSource) {
9+
self.signInSource = signInSource
10+
}
11+
712
public func execute(from: UIViewController?) {
813
continueWithDotCom(navigationController: from?.navigationController)
914
}
@@ -15,7 +20,7 @@ private extension NavigateToEnterAccount {
1520
DDLogError("Failed to navigate from LoginPrologueViewController to GetStartedViewController")
1621
return
1722
}
18-
vc.source = .wpCom
23+
vc.source = signInSource
1924

2025
navigationController?.pushViewController(vc, animated: true)
2126
}

WordPressAuthenticator/Signin/AppleAuthenticator.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ private extension AppleAuthenticator {
172172
fatalError()
173173
}
174174

175-
authenticationDelegate.presentLoginEpilogue(in: navigationController, for: credentials) {}
175+
authenticationDelegate.presentLoginEpilogue(in: navigationController,
176+
for: credentials,
177+
source: WordPressAuthenticator.shared.signInSource) {}
176178
}
177179

178180
func signupFailed(with error: Error) {

WordPressAuthenticator/Signin/LoginViewController.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ open class LoginViewController: NUXViewController, LoginFacadeDelegate {
144144
fatalError()
145145
}
146146

147-
authenticationDelegate.presentLoginEpilogue(in: navigationController, for: credentials) { [weak self] in
147+
authenticationDelegate.presentLoginEpilogue(in: navigationController,
148+
for: credentials,
149+
source: WordPressAuthenticator.shared.signInSource) { [weak self] in
148150
self?.dismissBlock?(false)
149151
}
150152
}

WordPressAuthenticator/Unified Auth/StoredCredentialsAuthenticator.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,10 @@ extension StoredCredentialsAuthenticator {
179179
return
180180
}
181181

182-
authenticationDelegate.presentLoginEpilogue(in: navigationController, for: credentials, onDismiss: {})
182+
authenticationDelegate.presentLoginEpilogue(in: navigationController,
183+
for: credentials,
184+
source: WordPressAuthenticator.shared.signInSource,
185+
onDismiss: {})
183186
}
184187

185188
/// Presents the login email screen, displaying the specified error. This is useful

WordPressAuthenticator/Unified Auth/View Related/Get Started/GetStartedViewController.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import SafariServices
33
import WordPressKit
44

55
/// The source for the sign in flow for external tracking.
6-
public enum SignInSource {
6+
public enum SignInSource: Equatable {
77
/// Initiated from the WP.com login CTA.
88
case wpCom
99
/// Initiated from the WP.com login flow that starts with site address.
1010
case wpComSiteAddress
11+
/// Other source identifier from the host app.
12+
case custom(source: String)
1113
}
1214

1315
/// The error during the sign in flow.
@@ -66,7 +68,11 @@ class GetStartedViewController: LoginViewController, NUXKeyboardResponder {
6668
// This is public so it can be set from StoredCredentialsAuthenticator.
6769
var errorMessage: String?
6870

69-
var source: SignInSource?
71+
var source: SignInSource? {
72+
didSet {
73+
WordPressAuthenticator.shared.signInSource = source
74+
}
75+
}
7076

7177
private var rows = [Row]()
7278
private var buttonViewController: NUXButtonViewController?

WordPressAuthenticatorTests/Navigation/NavigationToEnterAccountTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ final class NavigationToAccountTests: XCTestCase {
66
let origin = UIViewController()
77
let navigationController = MockNavigationController(rootViewController: origin)
88

9-
let command = NavigateToEnterAccount()
9+
let command = NavigateToEnterAccount(signInSource: .wpCom)
1010
command.execute(from: origin)
1111

1212
let pushedViewController = navigationController.pushedViewController

0 commit comments

Comments
 (0)