Skip to content

[WOOMOB-3799] Propagate and persist custom authentication endpoints (2/3) - #16397

Merged
hichamboushaba merged 5 commits into
trunkfrom
issue/WOOMOB-3799-auth-endpoint-plumbing
Aug 14, 2026
Merged

[WOOMOB-3799] Propagate and persist custom authentication endpoints (2/3)#16397
hichamboushaba merged 5 commits into
trunkfrom
issue/WOOMOB-3799-auth-endpoint-plumbing

Conversation

@hichamboushaba

@hichamboushaba hichamboushaba commented Aug 9, 2026

Copy link
Copy Markdown
Member

Description

Fixes WOOMOB-3799

Part 2 of 3, stacked on #16396 and followed by #16398.

This is one direct-site-credentials fix split into three PRs for review; the parts are not intended to ship independently. Review this diff against PR1's head. Merge order is 1 → 2 → 3, once the whole stack is approved.

PR1 can verify custom cookie-authentication endpoints, but the app still needs to carry those values through authentication, preserve meaningful failures, and store proven endpoints safely. This PR adds that plumbing without adding user-facing recovery UI.

The changes fall into three areas:

  1. Authentication and nonce refresh

    • Structured endpoints are used for initial nonce acquisition and later cookie-authenticated REST requests.
    • A protected request only runs with an available nonce. If initial acquisition fails, the REST callback is not invoked.
    • If a cached nonce is rejected and refreshing it fails, the original REST request runs only once and the refresh failure is returned.
  2. Failure provenance

    • The loginEntryVerified signal from PR1 reaches the app, so a failure after a proven sign-in page is not misreported as an unknown custom login URL.
    • Nonce-stage failures keep their useful type and message while dropping their HTTP response metadata. This prevents a login/admin 404 from being mistaken for a stale REST root, or a nonce status from being interpreted as an Application Password endpoint result.
  3. Persistence and refresh

    • Saving custom endpoints succeeds only after the site update affects a row and the stored SiteModel can be reloaded with the normalized values.
    • Dispatch, zero-row, reload, or value-mismatch failures restore the caller's original in-memory fields and surface the failure to the caller.
    • Later site refreshes preserve verified custom endpoints while still allowing stale admin metadata previously inferred from the REST Application Password authorization URL to be replaced.

Review map:

  • CookieNonceAuthenticator.kt: endpoint-aware initial/refresh nonce flow and failure propagation.
  • SiteWPAPIRestClient.kt: verified endpoint preservation during site refresh.
  • WPApiSiteRepository.kt: endpoint forwarding plus persist-and-reload confirmation.
  • Three focused test files cover nonce failures, refresh behavior, stale metadata, and persistence failures.

This PR adds no strings or standalone UI. QR login, XML-RPC, and Application Password architecture remain unchanged.

Test Steps

Because custom endpoints cannot be entered until PR3, perform the custom-endpoint steps using the top-of-stack build.

  1. Sign in to a self-hosted store using standard WordPress endpoints and confirm authenticated data such as Orders and Products loads.
  2. Sign out, repeat with an incorrect password, and confirm no authenticated store content is shown.
  3. Using the top-of-stack build and a store with custom login/admin endpoints, complete native login, force-stop the app, relaunch it, and confirm the store opens without asking for either endpoint again.
  4. Refresh an authenticated screen after relaunch and confirm data loads through the persisted endpoint configuration without a browser or repeated login loop.

Images/gif

N/A — this PR contains authentication and persistence plumbing only.

  • I have considered if this change warrants release notes and have added them to RELEASE-NOTES.txt if necessary. Use the "[Internal]" label for non-user-facing changes.

The stack's single user-facing release note is owned by PR3.

@hichamboushaba hichamboushaba added this to the 25.5 milestone Aug 9, 2026
@hichamboushaba hichamboushaba added type: bug A confirmed bug. category: architecture Related to architecture such as the database, FluxC, Networking, Core Data, etc. category: unit tests Related to unit testing. feature: login Related to any part of the log in or sign in flow, or authentication. labels Aug 9, 2026
@wpmobilebot

wpmobilebot commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator

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

App NameWooCommerce Android
Platform📱 Mobile
FlavorJalapeno
Build TypeDebug
Build Number778
Version25.4-rc-1
Application IDcom.woocommerce.android.prealpha
Commitcdd77c4
Installation URL5sj6kaat1p56o
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@hichamboushaba
hichamboushaba force-pushed the issue/WOOMOB-3799-auth-endpoint-plumbing branch 2 times, most recently from 1f2a60a to 5d5891e Compare August 10, 2026 18:18
@hichamboushaba
hichamboushaba marked this pull request as ready for review August 10, 2026 18:35

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

AI Code Review - Found 1 potential issue

This is a careful, well-tested refactor of the cookie-nonce authentication flow. Highlights:

  • The public makeAuthenticatedWPAPIRequest signature change is safe: all callers (CookieNonceWPAPINetwork, WPApiApplicationPasswordsRestClient, JetpackWPAPIRestClient) use nonce.value and already return WPAPIResponse<T>, and they now benefit from a non-null nonce (Available).
  • Backwards compatibility is preserved via the retained authenticate(siteUrl, ...) overload and the default endpoints param on WPApiSiteRepository.login(...).
  • Short-circuiting on nonce-acquisition failure (nonce.toErrorResponse()) correctly produces an error with no volleyError, so it is not misread as a 404 by the outer retry logic.
  • Endpoint-preservation logic in SiteWPAPIRestClient (preserve verified/manual admin+login URLs, discard stale inferred ones) is sound and well covered by the new tests.

One minor edge case is flagged inline.

PR housekeeping
  • Applied repo AGENTS.md/CLAUDE.md guidance (FluxC data-layer conventions, Kotlin style, no wildcard imports).
  • Test coverage is strong across the changed behavior; no gaps of concern.

Automatic review · claude-opus-4-8 · Workflow run

How to reply to a finding

Reply on this review (or inline at the line the finding refers to) with one of:

  • @claude addressed - I made the change. Bot verifies against the next diff before marking resolved.
  • @claude rejected: <reason> - Will not fix; reason gets quoted on the next review.
  • @claude not-applicable - Finding does not apply (wrong file, already covered elsewhere, etc.).

The bot honours these on the next review pass.

@hichamboushaba hichamboushaba added the status: do not merge Dependent on another PR, ready for review but not ready for merge. label Aug 10, 2026
@AdamGrzybkowski AdamGrzybkowski self-assigned this Aug 11, 2026

@AdamGrzybkowski AdamGrzybkowski left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great work! :shipit:

@hichamboushaba hichamboushaba removed the status: do not merge Dependent on another PR, ready for review but not ready for merge. label Aug 14, 2026
Base automatically changed from issue/WOOMOB-3799-cookie-nonce-endpoints to trunk August 14, 2026 09:32
@hichamboushaba
hichamboushaba force-pushed the issue/WOOMOB-3799-auth-endpoint-plumbing branch from 64960f6 to cdd77c4 Compare August 14, 2026 09:33
@hichamboushaba
hichamboushaba merged commit 5a66213 into trunk Aug 14, 2026
16 checks passed
@hichamboushaba
hichamboushaba deleted the issue/WOOMOB-3799-auth-endpoint-plumbing branch August 14, 2026 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: architecture Related to architecture such as the database, FluxC, Networking, Core Data, etc. category: unit tests Related to unit testing. feature: login Related to any part of the log in or sign in flow, or authentication. type: bug A confirmed bug.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants