Add Magic Link (passwordless) login feature#326
Draft
Sogl wants to merge 2 commits intogetgrav:developfrom
Draft
Add Magic Link (passwordless) login feature#326Sogl wants to merge 2 commits intogetgrav:developfrom
Sogl wants to merge 2 commits intogetgrav:developfrom
Conversation
- Add taskMagicRequest endpoint with IP and user rate limiting - Add handleMagicLogin handler (token validation, TTL, single-use) - Add userLoginAuthenticateByMagic listener (priority 10004) - Add addMagicPage handler with magic_link.enabled guard - Add Login::sendMagicLoginEmail() method - Add magic request page (pages/magic.md) and templates - Add 'Login by link' button on login form (conditional on enabled) - Add blueprints.yaml settings for magic_link section - Add magic_link defaults to login.yaml - Add en.yaml and ru.yaml i18n keys for magic link flow - Fix magic-login email templates: use author instead of actor.fullname - Security: crypto-random token, SHA-256 hash stored, invalidate before login() - Anti-enumeration: neutral response regardless of account state - Update README with Magic Link section
2f46b78 to
11d012a
Compare
847d21d to
5826eff
Compare
Contributor
Author
|
Added one follow-up commit with two fixes:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a Magic Link (passwordless) login feature to the Login plugin, allowing users to sign in via a one-time link sent to their email address — no password required.
Why
Passwordless login is increasingly common and expected, particularly for sites where users may not remember (or never set) a password — for example, after OAuth registration or admin-created accounts. A magic link is also a more user-friendly alternative to password reset for infrequent visitors.
What changed
Core logic
login.php—handleMagicLogin(): validates token, TTL, hash, invalidates token before login to prevent race-condition reuse, then runs the standardLogin::login()pipelinelogin.php—userLoginAuthenticateByMagic():onUserLoginAuthenticatelistener (priority 10004) that setsAUTHENTICATION_SUCCESSand stops propagation when themagic_linkoption is setlogin.php—addMagicPage(): serves the magic link request page, respectsmagic_link.enabledguardclasses/Login.php—sendMagicLoginEmail(): generates a cryptographically random token, stores its SHA-256 hash + expiry in the user file, sends the emailclasses/Controller.php—taskMagicRequest(): handles the email form submission with IP-level and per-user rate limiting; uses anti-enumeration (neutral response regardless of account existence)Templates & pages
pages/magic.md— default request page (email form)templates/magic.html.twig— page templatetemplates/partials/magic-form.html.twig— the email input formtemplates/partials/login-form.html.twig— added "Login by link" button (only shown whenmagic_link.enabled: true)templates/emails/login/magic-login.html.twig— HTML email templatetemplates/emails/login/magic-login.txt.twig— plain-text email templateConfiguration
blueprints.yaml— admin UI settings for the magic link sectionlogin.yaml— default config values (enabled: false,ttl: 10, rate limiting)i18n
languages/en.yaml— all magic link keyslanguages/ru.yaml— Russian translationsDocumentation
README.md— added Magic Link Login section with enabling instructions, flow description, and security notesSecurity considerations
random_bytes(32)— only its SHA-256 hash is stored in the user fileremember_meis never set via magic link logintwofais respected if enabledBackward compatibility
magic_link.enabled: false)