Skip to content

Commit e8b8829

Browse files
committed
docs: update for magic login
1 parent d07c0f9 commit e8b8829

File tree

7 files changed

+52
-18
lines changed

7 files changed

+52
-18
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ and authorization purposes in web applications.
5454
* Stateless authentication using Personal Access Tokens
5555
* Optional Email verification on account registration
5656
* Optional Email-based Two-Factor Authentication after login
57-
* Magic Link Login when a user forgets their password
57+
* Magic Login when a user forgets their password
5858
* Flexible Groups-based access control (think Roles, but more flexible)
5959
* Users can be granted additional Permissions
6060

docs/customization/extending_controllers.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ various parts of the authentication process:
88
- **ActionController** handles the after-login and after-registration actions, like Two Factor Authentication and Email Verification.
99
- **LoginController** handles the login process.
1010
- **RegisterController** handles the registration process. Overriding this class allows you to customize the User Provider, the User Entity, and the validation rules.
11-
- **MagicLinkController** handles the "lost password" process that allows a user to login with a link sent to their email. This allows you to
12-
override the message that is displayed to a user to describe what is happening, if you'd like to provide more information than simply swapping out the view used.
11+
- **MagicLinkController** handles the password-recovery and password-less login flow. It can deliver authentication credentials as a one-time login link or a one-time code (OTP) via email, depending on configuration. Developers may extend this controller to customize user-facing messages, providing clear context about the selected magic login method instead of only swapping view templates.
1312

1413
## How to Extend
1514

docs/customization/route_config.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ The above code registers the following routes:
5757
| POST | {locale}/login/magic-link | » | \CodeIgniter\Shield\Controllers\MagicLinkController::loginAction | | toolbar |
5858
| POST | {locale}/auth/a/handle | auth-action-handle | \CodeIgniter\Shield\Controllers\ActionController::handle | | toolbar |
5959
| POST | {locale}/auth/a/verify | auth-action-verify | \CodeIgniter\Shield\Controllers\ActionController::verify | | toolbar |
60+
| POST | {locale}/verify-magic-link | verify-magic-link | \CodeIgniter\Shield\Controllers\MagicLinkController::verify | | toolbar |
6061
+--------+----------------------------------+--------------------+--------------------------------------------------------------------+----------------+---------------+
6162
```
6263

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ The primary goals for Shield are:
2020
- **Stateless Authentication** using **Access Token**, **HMAC SHA256 Token**, or **JWT**
2121
- Optional **Email verification** on account registration
2222
- Optional **Email-based Two-Factor Authentication** after login
23-
- **Magic Link Login** when a user forgets their password
23+
- **Magic Login** when a user forgets their password
2424
- Flexible **Group-based Access Control** (think Roles, but more flexible), and users can be granted additional **Permissions**
2525
- A simple **Auth Helper** that provides access to the most common auth actions
2626
- Save initial settings in your code, so it can be in version control, but can also be updated in the database, thanks to our [Settings](https://github.com/codeigniter4/settings) library

docs/references/authentication/session.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ The following is a list of Events and Logging for Session Authenticator.
126126
- Send remember-me cookie w/o session cookie
127127
- OK → no event
128128
- NG → no event
129-
- Magic-link
129+
- Magic-login
130130
1. Post email
131131
- OK → no event
132132
- NG → no event

docs/references/events.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Events::on('failedLogin', function($credentials) {
4747
// Outputs: ['email' => 'foo@example.com'];
4848
```
4949

50-
When the magic link login fails, the following array will be provided:
50+
When the magic login fails, the following array will be provided:
5151

5252
```php
5353
['magicLinkToken' => 'the token value used']
@@ -59,7 +59,7 @@ Fired immediately after a successful logout. The only argument is the `User` ent
5959

6060
#### magicLogin
6161

62-
Fired when a user has been successfully logged in via a magic link. This event does not have any parameters passed in. The authenticated user can be discovered through the `auth()` helper.
62+
Fired when a user has been successfully logged in via a magic login. This event does not have any parameters passed in. The authenticated user can be discovered through the `auth()` helper.
6363

6464
```php
6565
Events::on('magicLogin', function() {

docs/references/magic_link_login.md

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,77 @@
1-
# Magic Link Login
1+
# Magic Login
22

3-
Magic Link Login is a feature that allows users to log in if they forget their
4-
password.
3+
Magic Login is an authentication feature that allows users to sign in using a one-time login link(magic link) or a one-time verification code(opt-code) sent to their email. This method provides a secure, password-less entry option, and is especially valuable for users who have forgotten their password, offering a fast and friction-free recovery experience.
54

65
## Configuration
76

8-
### Configure Magic Link Login Functionality
7+
### Configure Magic Login Functionality
98

10-
Magic Link Login functionality is enabled by default.
9+
Magic Login functionality is enabled by default.
1110
You can change it within the **app/Config/Auth.php** file.
1211

1312
```php
1413
public bool $allowMagicLinkLogins = true;
1514
```
1615

17-
### Magic Link Lifetime
16+
### Magic Login Mode
1817

19-
By default, Magic Link can be used for 1 hour. This can be easily modified
18+
Defines the format and type of the one-time credential sent to users for magic login. The system supports both password-less login via email link as well as multiple one-time verification code formats. The delivery method and code type are specified using configurable mode patterns.
19+
20+
#### Supported Modes
21+
22+
`clickable` (default) — Sends a secure, one-time login link to the user’s email that can be clicked to authenticate instantly.
23+
24+
`<length>-numeric` — Sends a numeric one-time code with the defined character length.
25+
26+
`<length>-alpha` — Sends an alphabet-only one-time code with the defined character length.
27+
28+
`<length>-alnum` — Sends an alphanumeric one-time code with the defined character length.
29+
30+
`<length>-oneof` — Sends a one-time code with the defined length, while the system automatically selects the random code type from: numeric, alpha, or alnum.
31+
32+
```php
33+
public string $magicLoginMode = '8-oneof';
34+
```
35+
36+
### Magic Lifetime
37+
38+
By default, Magic can be used for 1 hour. This can be easily modified
2039
in the **app/Config/Auth.php** file.
2140

2241
```php
2342
public int $magicLinkLifetime = HOUR;
2443
```
2544

45+
!!! warning
46+
47+
One-time numeric codes (such as a 6-digit `6-numeric` format) are inherently more predictable and may be easier to guess. If you plan to deliver a one-time password (OTP) instead of a magic link, we strongly recommend using the `6-oneof` credential mode, which allows the system to randomly generate numeric, alphabetic, or alphanumeric codes. This approach significantly increases unpredictability and makes OTP guessing more difficult.
48+
49+
Additionally, to further mitigate brute-force and code-guessing risks, it is advisable to reduce the `$magicLinkLifetime` to a short window of only a few minutes (e.g., 120–300 seconds).
50+
51+
2652
### Bot Detection
2753

28-
Some apps or devices may try to be "too helpful" by automatically visiting links - for example, to check if they're safe or to prepare for read-aloud features. Since this is a one-time magic link, such automated visits could invalidate it. To prevent this, Shield relies on the framework's `UserAgents::robots` config property (**app/Config/UserAgents.php**) to filter out requests that are likely initiated by non-human agents.
54+
Some apps or devices may try to be "too helpful" by automatically visiting links - for example, to check if they're safe or to prepare for read-aloud features. Since this is a one-time magic link(`clickable`), such automated visits could invalidate it. To prevent this, Shield relies on the framework's `UserAgents::robots` config property (**app/Config/UserAgents.php**) to filter out requests that are likely initiated by non-human agents.
2955

30-
## Responding to Magic Link Logins
56+
Unlike one-time login links, one-time codes (OTP) are not impacted by automated URL visits, since they require manual user input to complete authentication. Therefore, if your application delivers OTP(`6-numeric`,`6-alpha`,`6-alnum`,`6-oneof`) credentials, bot auto-visits do not introduce the same credential-invalidation risk.
57+
58+
## Responding to Magic Logins
3159

3260
!!! note
3361

3462
You need to configure **app/Config/Email.php** to allow Shield to send emails. See [Installation](../getting_started/install.md#initial-setup).
3563

36-
Magic Link logins allow a user that has forgotten their password to have an email sent with a unique, one-time login link. Once they've logged in you can decide how to respond. In some cases, you might want to redirect them to a special page where they must choose a new password. In other cases, you might simply want to display a one-time message prompting them to go to their account page and choose a new password.
64+
Magic Login allows users who have forgotten their password to authenticate using a secure, one-time credential delivered via email. Depending on configuration or product requirements, this credential can be either:
65+
66+
1. unique, single-use login link
67+
68+
2. one-time opt-code for manual entry in the application
69+
70+
After authentication succeeds, the system behavior is up to the developer. Possible responses include redirecting the user to a dedicated password reset screen, or displaying a one-time confirmation message encouraging them to update their password from their account settings.
3771

3872
### Session Notification
3973

40-
You can detect if a user has finished the magic link login by checking for a session value, `magicLogin`. If they have recently completed the flow, it will exist and have a value of `true`.
74+
You can detect if a user has finished the magic login by checking for a session value, `magicLogin`. If they have recently completed the flow, it will exist and have a value of `true`.
4175

4276
```php
4377
if (session('magicLogin')) {

0 commit comments

Comments
 (0)