feat(reader-activation): frontend registration API for integrations#4626
feat(reader-activation): frontend registration API for integrations#4626jason10lee wants to merge 32 commits intotrunkfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a public frontend “integration registration” flow for Reader Activation, exposing a new REST endpoint plus a JS API to let third-party scripts register readers from the browser with similar protections as the existing auth modal flow.
Changes:
- Adds
/newspack/v1/reader-activation/registerREST endpoint with integration ID/key validation, honeypot, optional reCAPTCHA v3 verification, and per-IP rate limiting. - Localizes registered integrations + deterministic HMAC keys and the endpoint URL into
newspack_ras_config. - Adds
newspackReaderActivation.register()JS method and introduces unit tests for endpoint behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
includes/reader-activation/class-reader-activation.php |
Localizes integration config and registers a new REST endpoint implementing the server-side registration flow + mitigations. |
src/reader-activation/index.js |
Adds a register() method on the Reader Activation JS global to perform validation, optional reCAPTCHA token acquisition, and POST to the REST endpoint. |
tests/unit-tests/reader-registration-endpoint.php |
Adds unit tests covering success, validation errors, honeypot behavior, logged-in rejection, and rate limiting for the new endpoint. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…a for logged-in readers
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…PI looks prohibitively messy
All Submissions:
Changes proposed in this Pull Request:
This PR adds a frontend reader registration API that allows third-party integrations to register readers from the browser, consistent with the existing
process_auth_form()registration flow.Integrations register via the
newspack_frontend_registration_integrationsfilter. Each integration receives a deterministic HMAC key (derived fromwp_salt('auth')) that is localized to the page. A newregister()method on thenewspackReaderActivationJS global handles the full flow: client-side validation, reCAPTCHA v3 token acquisition (when configured), and POST to a new REST endpoint at/newspack/v1/reader-activation/register. On success, the reader is created, authenticated, and the in-memory reader state is updated — matching the behavior of the existing auth modal registration.Security mitigations follow the same patterns used by
process_auth_form():hash_equalsfor timing-safe comparison)emailis the decoy,npecarries the real address (same convention as the auth form)Recaptcha::verify_captcha()bridgewp_cache_incrwith a transient fallback for sites without persistent object cacheAddresses NPPD-1070.
How to test the changes in this Pull Request:
We'll be adding a WisePops integration, but while we firm up the foundation, you'll need to create a stub integration to test:
Add a mu-plugin to register a test integration:
Visit the site frontend, view page source, and search for
newspack_ras_config. Confirm it containsfrontend_registration_integrationswith amanual-testentry that has akeyvalue, and afrontend_registration_urlpointing to the REST endpoint.Successful registration — in the browser console:
Expected:
Success: { success: true, status: "created", email: "test@example.com" }. Verify the user appears in wp-admin Users with display name "Test User" and thecustomerrole.Duplicate registration — run the same call again with the same email:
Expected:
Expected: reader_already_exists A reader with this email address is already registered.Unknown integration — use an unregistered integration ID:
Expected: immediate client-side rejection
Expected: Unknown integration: unknown-toolInvalid email:
Expected: client-side rejection
Expected: Invalid email address.Clean up: delete test users from wp-admin and remove the mu-plugin.
Other information: