Skip to content

Show password login webview and prepare internal architecture #21855

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

Merged

Conversation

adalpari
Copy link
Contributor

@adalpari adalpari commented May 5, 2025

Description

This PR is adding a new step for the Application Password login in the LoginActivity. See the previous discarded place for this logic: #21852
In this new iteration we are showing to the user the authentication webview and intercepting the callback url. NOTE: the callback is yet not handled. That will be done in the next iteration: handling it and storing it.

Testing instructions

  1. Run the app and test BOTH login flow to be sure nothing is broken. They should work as always.
  2. Open the project and, in LoginActivity, uncomment line 705
Screenshot 2025-05-05 at 15 03 08 3. Run the app again. And login in a self-hosted site
  • Verify you see a log like: Found authorization for https://vanilla.wpmt.co URL: https://vanilla.wpmt.co/wp-admin/authorize-application.php?app_name=android-jetpack-client&success_url=jetpack%3A%2F%2Fwpcom-authorize

  • Verify you are redirected to the authentication webview

  1. Approve the connection
  • Verify you are redirected to the login screen (that's enough for now)
Screen.Recording.2025-05-05.at.15.49.53.mov

<!-

Consider testing the following yourself before requesting a review:

  • Compatibility with WordPress.com sites and self-hosted Jetpack sites
  • Both portrait and landscape orientations
  • Light and dark modes
  • Dynamic font sizes: larger, smaller and bold text
  • High contrast mode
  • Screen reader experience (e.g., Talkback)
  • Languages with large words or with letters/accents not frequently used in English
  • Right-to-left languages layout
  • Multi-tasking: split view and slide over

-->

@dangermattic
Copy link
Collaborator

dangermattic commented May 5, 2025

1 Warning
⚠️ PR is not assigned to a milestone.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Contributor

wpmobilebot commented May 5, 2025

WordPress📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress WordPress
FlavorJalapeno
Build TypeDebug
Versionpr21855-30a529b
Commit30a529b
Direct Downloadwordpress-prototype-build-pr21855-30a529b.apk
Note: Google Login is not supported on these builds.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented May 5, 2025

Jetpack📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack Jetpack
FlavorJalapeno
Build TypeDebug
Versionpr21855-30a529b
Commit30a529b
Direct Downloadjetpack-prototype-build-pr21855-30a529b.apk
Note: Google Login is not supported on these builds.

Copy link

codecov bot commented May 5, 2025

Codecov Report

Attention: Patch coverage is 50.00000% with 4 lines in your changes missing coverage. Please review.

Project coverage is 39.38%. Comparing base (f5f51ea) to head (30a529b).
Report is 2 commits behind head on trunk.

Files with missing lines Patch % Lines
...ress/android/ui/accounts/login/WPcomLoginHelper.kt 0.00% 4 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            trunk   #21855   +/-   ##
=======================================
  Coverage   39.38%   39.38%           
=======================================
  Files        2134     2133    -1     
  Lines      100053   100044    -9     
  Branches    15408    15408           
=======================================
  Hits        39406    39406           
+ Misses      57164    57155    -9     
  Partials     3483     3483           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@adalpari adalpari requested a review from Copilot May 5, 2025 13:53
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a new password login flow by presenting an authentication webview for API discovery and prepares the internal architecture for handling callback URLs in a subsequent iteration. Key changes include removing the obsolete LoginSiteAddressViewModel and its tests, updating LoginActivity to use a dedicated CustomTabsIntent helper for launching webviews, and enhancing LoginViewModel to perform API discovery with consolidated error handling and analytics tracking.

Reviewed Changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
libs/login/src/main/java/org/wordpress/android/login/viewmodel/LoginSiteAddressViewModel.kt Removed obsolete view model used for API discovery
libs/login/src/main/java/org/wordpress/android/login/LoginSiteAddressFragment.kt Removed dependency on LoginSiteAddressViewModel and its API discovery call
WordPress/src/test/java/org/wordpress/android/ui/accounts/LoginViewModelTest.kt Added tests validating the new API discovery flow in LoginViewModel
WordPress/src/test/java/org/wordpress/android/login/viewmodel/LoginSiteAddressViewModelTest.kt Removed tests for the deleted view model
WordPress/src/main/java/org/wordpress/android/ui/accounts/login/WPcomLoginHelper.kt Added a helper to append query parameters to the authorization URL
WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginViewModel.kt Refactored API discovery method to integrate with WPcomLoginHelper and enhanced logging/analytics
WordPress/src/main/java/org/wordpress/android/ui/accounts/LoginActivity.java Simplified custom tabs handling and introduced a new method to launch the application password flow
WordPress/src/main/java/org/wordpress/android/modules/ViewModelModule.java Removed the dependency injection binding for the deleted view model
Files not reviewed (1)
  • libs/login/build.gradle: Language not supported
Comments suppressed due to low confidence (2)

WordPress/src/main/java/org/wordpress/android/modules/ViewModelModule.java:451

  • Ensure that removing the LoginSiteAddressViewModel binding does not affect any existing dependency injections in the app.
@Binds @IntoMap @ViewModelKey(LoginSiteAddressViewModel.class)

libs/login/src/main/java/org/wordpress/android/login/LoginSiteAddressFragment.kt:190

  • Add a clarifying comment to explain the migration of API discovery logic, indicating where and how this functionality is now handled.
//            viewModel.runApiDiscovery(cleanedUrl)

Comment on lines +53 to +56
} catch (throwable: Throwable) {
Log.e("WP_RS", "VM: Error during API discovery for $url", throwable)
AnalyticsTracker.track(AnalyticsTracker.Stat.BACKGROUND_REST_AUTODISCOVERY_FAILED)
""
Copy link
Preview

Copilot AI May 5, 2025

Choose a reason for hiding this comment

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

Consider catching specific exceptions instead of Throwable to avoid masking underlying issues during API discovery.

Suggested change
} catch (throwable: Throwable) {
Log.e("WP_RS", "VM: Error during API discovery for $url", throwable)
AnalyticsTracker.track(AnalyticsTracker.Stat.BACKGROUND_REST_AUTODISCOVERY_FAILED)
""
} catch (e: IOException) {
Log.e("WP_RS", "VM: Network error during API discovery for $url", e)
AnalyticsTracker.track(AnalyticsTracker.Stat.BACKGROUND_REST_AUTODISCOVERY_FAILED)
""
} catch (e: IllegalArgumentException) {
Log.e("WP_RS", "VM: Invalid argument during API discovery for $url", e)
AnalyticsTracker.track(AnalyticsTracker.Stat.BACKGROUND_REST_AUTODISCOVERY_FAILED)
""

Copilot uses AI. Check for mistakes.

@adalpari adalpari requested a review from nbradbury May 5, 2025 14:44
@adalpari adalpari marked this pull request as ready for review May 9, 2025 10:05
Copy link

sonarqubecloud bot commented May 9, 2025

@nbradbury nbradbury self-assigned this May 9, 2025
Copy link
Contributor

@nbradbury nbradbury left a comment

Choose a reason for hiding this comment

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

Looks good - glad to see some progress on this! Feel free to merge when ready :shipit:

@adalpari adalpari merged commit 0fa6d8b into trunk May 9, 2025
26 checks passed
@adalpari adalpari deleted the feat/CMM-328-Show-Password-Login-webview-for-background-job branch May 9, 2025 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants