-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Replace native WP.com sign in with web-based sign in #23675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
2212307
89816af
3660f1c
319f7e3
43409de
37d8246
7e582a0
a218717
7389522
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| 25.5 | ||
| ----- | ||
|
|
||
| * [***] Use web-based sign-in flow (hidden under a feature flag) [#23675] | ||
|
|
||
| 25.4 | ||
| ----- | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import AuthenticationServices | ||
| import Foundation | ||
| import UIKit | ||
| import WordPressAuthenticator | ||
|
|
||
| import Alamofire | ||
|
|
||
|
|
@@ -17,7 +18,64 @@ struct WordPressDotComAuthenticator { | |
| case unknown(Swift.Error) | ||
| } | ||
|
|
||
| @MainActor | ||
| func signIn(from viewController: UINavigationController) async { | ||
| let token: String | ||
| do { | ||
| token = try await authenticate(from: viewController) | ||
| } catch { | ||
| if let error = error as? WordPressDotComAuthenticator.Error { | ||
| // Show an alert for non-cancellation errors. | ||
| // `.cancelled` error is thrown when user taps the cancel button in the presented Safari view controller. | ||
| if case .cancelled = error { | ||
| // Do nothing | ||
| } else { | ||
| // All other errors are unexpected. | ||
| wpAssertionFailure("WP.com web login failed", userInfo: ["error": "\(error)"]) | ||
|
|
||
| let alert = UIAlertController( | ||
| title: NSLocalizedString("wpComLogin.error.title", value: "Error", comment: "Error"), | ||
| message: SharedStrings.Error.generic, | ||
| preferredStyle: .alert | ||
| ) | ||
| alert.addAction(UIAlertAction(title: SharedStrings.Button.close, style: .cancel, handler: nil)) | ||
| viewController.present(alert, animated: true) | ||
| } | ||
| } else { | ||
| wpAssertionFailure("WP.com web login failed", userInfo: ["error": "\(error)"]) | ||
| } | ||
| return | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (nit) Extract the first part into a separate method so that there is no There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in 43409de |
||
| } | ||
|
|
||
| let delegate = WordPressAuthenticator.shared.delegate! | ||
| let credentials = AuthenticatorCredentials(wpcom: WordPressComCredentials(authToken: token, isJetpackLogin: false, multifactor: false)) | ||
| SVProgressHUD.show() | ||
| delegate.sync(credentials: credentials) { | ||
| SVProgressHUD.dismiss() | ||
|
|
||
| delegate.presentLoginEpilogue( | ||
| in: viewController, | ||
| for: credentials, | ||
| source: .custom(source: "web-login"), | ||
| onDismiss: { /* Do nothing */ } | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| func authenticate(from viewController: UIViewController) async throws -> String { | ||
| WPAnalytics.track(.wpcomWebSignIn, properties: ["stage": "start"]) | ||
|
|
||
| do { | ||
| let value = try await _authenticate(from: viewController) | ||
| WPAnalytics.track(.wpcomWebSignIn, properties: ["stage": "success"]) | ||
| return value | ||
| } catch { | ||
| WPAnalytics.track(.wpcomWebSignIn, properties: ["stage": "error", "error": "\(error)"]) | ||
| throw error | ||
| } | ||
| } | ||
|
|
||
| private func _authenticate(from viewController: UIViewController) async throws -> String { | ||
| let clientId = ApiCredentials.client | ||
| let clientSecret = ApiCredentials.secret | ||
| let redirectURI = "x-wordpress-app://oauth2-callback" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,24 @@ protocol WordPressAuthenticatorProtocol { | |
|
|
||
| extension WordPressAuthenticator: WordPressAuthenticatorProtocol { | ||
| static func loginUI() -> UIViewController? { | ||
| Self.loginUI(showCancel: false, restrictToWPCom: false, onLoginButtonTapped: nil) | ||
| Self.loginUI(showCancel: false, restrictToWPCom: false, onLoginButtonTapped: nil, continueWithDotCom: { viewController in | ||
| // TODO: Replce with a remote feature flag. | ||
| // Enable web-based login for debug builds until the remote feature flag is available. | ||
| #if DEBUG | ||
| let webLoginEnabled = true | ||
|
||
| #else | ||
| let webLoginEnabled = false | ||
| #endif | ||
|
|
||
| guard webLoginEnabled, let navigationController = viewController.navigationController else { | ||
| return false | ||
| } | ||
|
|
||
| Task { @MainActor in | ||
| await WordPressDotComAuthenticator().signIn(from: navigationController) | ||
| } | ||
|
|
||
| return true | ||
| }) | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The animation at the top is distracting.
Untitled.mp4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why it looks like this for me. It's different on your recording. I think there is a bug with the first welcome page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we present this login screen as a pushed navigation item instead of a popover?
That'd be more consistent with the current setup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 I don't think there is an API for that. https://developer.apple.com/documentation/authenticationservices/aswebauthenticationsession
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I thought we had the ability to do it in the SwiftUI setup for self-hosted sites, but it's ok – we can dig into that further once we're not relying on a bunch of WPAuthenticator stuff anymore.
I have a few suggestions about this in #23702
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just checked. The application password flow for self-hosted site also presents Safari view as a modal.