Skip to content

Conversation

@itsmeichigo
Copy link
Contributor

@itsmeichigo itsmeichigo commented Feb 17, 2025

Closes: #15147

Description

This PR implements the improvements suggested in pe5sF9-3QB-p2. Authenticated web view now handles auto authentication in the web view for the following cases:

  • WordPress.com authenticated:
    • wordpress.com supported URLs.
    • Jetpack SSO sites (including both Atomic and self-hosted sites)
  • Site Credentials authenticated (assuming native login worked for the authentication)

Also, the web view now catches the authentication failures to navigate the user to the original URL in these cases.

Steps to reproduce

Important

  • To avoid any false positives, please ensure that you are signed out from the WebView after each test by tapping the WordPress logout button manually in the WebView.
  • If you changed the Jetpack SSO module settings for a site, ensure that you restart the app to fetch the new site modules.
  • WPS Hide Login that I used in some tests below has issues with redirection, so expect some issues. I couldn't find an alternative plugin that works better, in the past we used to use WP Hide & Security Enhancer which worked well, but its free version doesn't seem to work with Jurassic Ninja sites nor Pressable sites anymore.
  • Jetpack SSO settings can be accessed from Jetpack Settings in wp-admin (wp-admin/admin.php?page=jetpack#/settings)
TC1: WordPress.com authenticated with a wordpress.com supported link
  1. Sign in using WordPress.com
  2. Open the payments hub.
  3. Tap on "order card reader"
  4. Tap on Log In in the hamburger menu.
  5. Confirm that your WordPress.com account is signed in and suggested as first option.
TC2: WordPress.com authenticated with a Jetpack SSO site
  1. Sign in using WordPress.com
  2. Select a Jetpack website (Atomic or self-hosted) where Jetpack SSO is enabled (can be enabled from Jetpack settings in wp-admin).
  3. Open the dashboard screen.
  4. If needed, add the performance card.
  5. Tap on "View all store analytics"
  6. Tap on "See report" in one of the analytics cards.
  7. Confirm that you are auto-authenticated to your account.
  8. Optional: Set your site to coming soon wp-admin > WooCommerce Settings > Site Visibility. Then on the app, select a published product > View Product in Store and confirm that the product page can be displayed successfully with a banner at the bottom about the coming soon state.
TC3: WordPress.com authenticated with a Jetpack site without SSO
  1. Sign in using WordPress.com
  2. Select a Jetpack website where Jetpack SSO is disabled (can be disabled from Jetpack settings in wp-admin).
  3. Open the dashboard screen.
  4. If needed, add the performance card.
  5. Tap on "View all store analytics"
  6. Tap on "See report" in one of the analytics cards.
  7. Confirm that you see the WPOrg login page instead of being authenticated automatically.
TC4: Site Credentials authenticated using web authorization
  1. Use a self-hosted site.
  2. Install WPS Hide Login plugin.
  3. Open WPS Hide Login settings, and use a custom login URL (Enter the same URL in the redirection URL too).
  4. Open the app and sign in (you might need to perform the Web Authorization twice, because WPS Hide Login doesn't work well with the redirection, but I didn't find a better alternative)
  5. Open the dashboard screen.
  6. If needed, add the performance card.
  7. Tap on "View all store analytics"
  8. Tap on "See report" in one of the analytics cards.
  9. Confirm that you see the WPOrg login page instead of being authenticated automatically.
TC5: Site Credentials authenticated natively
  1. Use a self-hosted site that doesn't use any security measures that could break the native login.
  2. Sign in using site credentials.
  3. Open the dashboard screen.
  4. If needed, add the performance card.
  5. Tap on "View all store analytics"
  6. Tap on "See report" in one of the analytics cards.
  7. Confirm that you are auto-authenticated to your account.
TC6: Site Credentials authenticated natively, but uses custom login URL now
  1. Use a self-hosted site that doesn't use any security measures that could break the native login.
  2. Sign in using site credentials.
  3. Install WPS Hide Login plugin.
  4. Configure WPS Hide Login to use a custom login URL (Enter the same URL in the redirection URL too).
  5. Open the dashboard screen.
  6. If needed, add the performance card.
  7. Tap on "View all store analytics"
  8. Tap on "See report" in one of the analytics cards.
  9. Confirm that the login screen is shown (which is expected in this case given the custom login URL).

Testing information

  • Tested all the cases above using simulator iPhone 16 Pro iOS 18.1 and 18.2.
  • Unit tests were added to verify the logic for authentication flow checks.

Screenshots

N/A


  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

Reviewer (or Author, in the case of optional code reviews):

Please make sure these conditions are met before approving the PR, or request changes if the PR needs improvement:

  • The PR is small and has a clear, single focus, or a valid explanation is provided in the description. If needed, please request to split it into smaller PRs.
  • Ensure Adequate Unit Test Coverage: The changes are reasonably covered by unit tests or an explanation is provided in the PR description.
  • Manual Testing: The author listed all the tests they ran, including smoke tests when needed (e.g., for refactorings). The reviewer confirmed that the PR works as expected on all devices (phone/tablet) and no regressions are added.

@itsmeichigo itsmeichigo added type: task An internally driven task. feature: core Core work. See "category: tooling" and "category: architecture" labels Feb 17, 2025
@itsmeichigo itsmeichigo added this to the 21.8 milestone Feb 17, 2025
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Feb 17, 2025

WooCommerce iOS📲 You can test the changes from this Pull Request in WooCommerce iOS by scanning the QR code below to install the corresponding build.

App NameWooCommerce iOS WooCommerce iOS
Build Numberpr15164-75ec99a
Version21.7
Bundle IDcom.automattic.alpha.woocommerce
Commit75ec99a
App Center BuildWooCommerce - Prototype Builds #13063
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

Base automatically changed from task/15147-check-site-sso to trunk February 18, 2025 02:49
Comment on lines -1045 to -1073
let stores = ServiceLocator.stores
guard let site = stores.sessionManager.defaultSite,
stores.shouldAuthenticateAdminPage(for: site) else {
WebviewHelper.launch(url.absoluteString, with: self)
return
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using authenticated web view controller now for all product preview - the web view now can check to see if authentication is possible. If not, it would just open the original URL.

@itsmeichigo itsmeichigo marked this pull request as ready for review February 18, 2025 12:16
@selanthiraiyan selanthiraiyan self-assigned this Feb 20, 2025
Copy link
Contributor

@selanthiraiyan selanthiraiyan left a comment

Choose a reason for hiding this comment

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

Nice work, Huong!

The code LGTM and tests as expected. 🚀


I am sharing a few observations just for information.

  1. I think the 8th point in TC3 is not relevant and should be removed.
  2. With WPS Hide Login installed I had to exit the web view during the login flow and try login again. I think this is expected as your mentioned in test instructions.
  3. With WPS Hide Login installed after logging in to the app, I had to logout of the web view before testing further to avoid false positives. This is expected as you mentioned in the test instructions.

} else {
loadContent()
/// Authentication logic differs depending on the destination URL and the current site.
/// More information: https://wp.me/pe5sF9-3Si
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// More information: https://wp.me/pe5sF9-3Si
/// More information: pe5sF9-3Si-p2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch! Fixed in e9d83df.

Comment on lines +130 to +132
guard isAuthenticationFailure else {
return false
}
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ Should we rename isAuthenticationFailure into isAuthenticationInProgress? If I understand this correctly, we are checking whether the current url is related to authentication and return false if the url is related to log. This lets the web view proceed further with the navigation and authentication.

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 believe isAuthenticationFailure makes more sense here, as the web view fails to handle the authentication (POST request) and attempts to load the login page (the HTLM page) instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice tests. ❤️

@dangermattic
Copy link
Collaborator

1 Warning
⚠️ This PR is assigned to the milestone 21.8. This milestone is due in less than 2 days.
Please make sure to get it merged by then or assign it to a milestone with a later deadline.

Generated by 🚫 Danger

@itsmeichigo
Copy link
Contributor Author

Thank you Sharma for the review!

I think the 8th point in TC3 is not relevant and should be removed.

I removed this from the PR description ✅

@itsmeichigo itsmeichigo merged commit 6e32098 into trunk Feb 20, 2025
13 checks passed
@itsmeichigo itsmeichigo deleted the task/15147-sso-authenticated-web-view branch February 20, 2025 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature: core Core work. See "category: tooling" and "category: architecture" type: task An internally driven task.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve the Authenticated Webview implementation

5 participants