-
Notifications
You must be signed in to change notification settings - Fork 49
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
feat: magic links #1668
feat: magic links #1668
Conversation
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 love how this code utilises common WP practices (like filtering stuff), has proper documentation, and tests ❤️
Co-authored-by: Adam Boro <[email protected]>
Co-authored-by: Adam Boro <[email protected]>
0cf90d0 implements another small change to the token. It was using a salted hash from |
# [1.86.0-alpha.1](v1.85.0...v1.86.0-alpha.1) (2022-07-01) ### Bug Fixes * **reader-revenue:** disable WC email if module will send email ([#1709](#1709)) ([48e1613](48e1613)), closes [#1699](#1699) ### Features * ads onboarding ([#1678](#1678)) ([80c0bf4](80c0bf4)) * disable deactivate and delete for required plugins ([#1712](#1712)) ([75afee8](75afee8)) * **experimental:** magic links ([#1668](#1668)) ([02d9f82](02d9f82)) * **reader-revenue:** prevent creating duplicate stripe webhooks ([#1710](#1710)) ([586e693](586e693))
🎉 This PR is included in version 1.86.0-alpha.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
# [1.86.0](v1.85.2...v1.86.0) (2022-07-11) ### Bug Fixes * **reader-revenue:** disable WC email if module will send email ([#1709](#1709)) ([48e1613](48e1613)), closes [#1699](#1699) ### Features * ads onboarding ([#1678](#1678)) ([80c0bf4](80c0bf4)) * disable deactivate and delete for required plugins ([#1712](#1712)) ([75afee8](75afee8)) * **experimental:** magic links ([#1668](#1668)) ([02d9f82](02d9f82)) * **reader-revenue:** prevent creating duplicate stripe webhooks ([#1710](#1710)) ([586e693](586e693))
🎉 This PR is included in version 1.86.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
All Submissions:
Changes proposed in this Pull Request:
This PR implements magic link functionality that should only be available to a "reader", as implemented by #1655.
Magic links are single-use authentication links that are sent to the user's registered email.
This implementation limits the number of simultaneous valid tokens to 5, which should be a safe amount in case the reader attempts to authenticate multiple devices at once. The limit is also a safety measure, because magic link creation, naturally, does not require authentication.
Also as a safety measure, magic links expire 30 minutes after creation.
This feature should only be available with reader activation enabled.
Self-Served vs. Admin-Generated
Magic links can be generated and sent by an anonymous user, these are self-served. Self-served links have a salted client hash attached to them. They are formed by the following arguments:
The random secret is stored locally through a cookie for client hash validation. If the client hash does not match, the magic link fails to authenticate.
Admin-generated links do not have a client hash and can be used by anyone.
Email
The sent email is minimalistic, filterable, and highly inspired by WP's
wp_new_user_notification()
. It serves the purpose of the functionality but for the "reader activation" project, all reader-related messaging should be tackled separately in a unified cohesive effort.Management
There are a few tools available for the management of a user's magic link support. An admin can:
Dashboard
CLI
A magic link can also be sent with WP-CLI:
How to test the changes in this Pull Request:
Make sure you have AMP Plus on, reader revenue configured with WooCommerce and a valid Stripe test account, and the experimental reader activation flag on your
wp-config.php
:Also confirm you have a way to intercept sent emails, either through Mailhog or a configured SMTP.
Admin-generated
The quickest simple test to a magic link is by sending as an admin:
my-account
pageAdmin management
Clearing tokens
Disabling magic links for a user
CLI
wp newspack magic-link send –help
and confirm you see appropriate instructionswp newspack magic-link send {email}
wp newspack magic-link send {user_id}
Self-served tokens
np_auth_link
my-account
pageClient hash validation
np_auth_link
cookie)Other information: