Skip to content

Commit a18c47c

Browse files
committed
small adjustments to phx.gen.auth guide
1 parent 76682de commit a18c47c

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

guides/authentication/mix_phx_gen_auth.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
> This guide assumes that you have gone through the [introductory guides](overview.html) and have a Phoenix application [up and running](up_and_running.html).
44
5-
The `mix phx.gen.auth` command generates a flexible, pre-built authentication system into your Phoenix app. This generator allows you to quickly move past the task of adding authentication to your codebase and stay focused on the real-world problem your application is trying to solve.
5+
The `mix phx.gen.auth` command generates a flexible, pre-built authentication system based on magic links into your Phoenix app. This generator allows you to quickly move past the task of adding authentication to your codebase and stay focused on the real-world problem your application is trying to solve.
66

77
## Getting started
88

@@ -76,11 +76,10 @@ The generated code ships with an authentication module with a handful of plugs t
7676

7777
* `fetch_current_user` - fetches the current user information if available
7878
* `require_authenticated_user` - must be invoked after `fetch_current_user` and requires that a current user exists and is authenticated
79-
* `redirect_if_user_is_authenticated` - used for the few pages that must not be available to authenticated users
79+
* `redirect_if_user_is_authenticated` - used for the few pages that must not be available to authenticated users (only generated for controller based authentication)
80+
* `require_sudo_mode` - used for pages that contain sensitive operations and enforces recent authentication
8081

81-
### Confirmation
82-
83-
The generated functionality ships with an account confirmation mechanism, where users have to confirm their account, typically by email. However, the generated code does not forbid users from using the application if their accounts have not yet been confirmed. You can add this functionality by customizing the `require_authenticated_user` in the `Auth` module to check for the `confirmed_at` field (and any other property you desire).
82+
There are similar `:on_mount` hooks for LiveView based authentication.
8483

8584
### Notifiers
8685

@@ -102,6 +101,10 @@ If your application is sensitive to enumeration attacks, you need to implement y
102101

103102
Furthermore, if you are concerned about enumeration attacks, beware of timing attacks too. For example, registering a new account typically involves additional work (such as writing to the database, sending emails, etc) compared to when an account already exists. Someone could measure the time taken to execute those additional tasks to enumerate emails. This applies to all endpoints (registration, confirmation, password recovery, etc.) that may send email, in-app notifications, etc.
104103

104+
### Confirmation and credential pre-stuffing attacks
105+
106+
The generated functionality ships with an account confirmation mechanism, where users have to confirm their account, typically by email. Furthermore, to prevent security issues, the generated code does forbid users from using the application if their accounts have not yet been confirmed. If you want to change this behavior, please refer to the ["Mixing magic link and password registration" section](Mix.Tasks.Phx.Gen.Auth.html#module-mixing-magic-link-and-password-registration) of `mix phx.gen.auth`.
107+
105108
### Case sensitiveness
106109

107110
The email lookup is made to be case-insensitive. Case-insensitive lookups are the default in MySQL and MSSQL. In SQLite3 we use [`COLLATE NOCASE`](https://www.sqlite.org/datatype3.html#collating_sequences) in the column definition to support it. In PostgreSQL, we use the [`citext` extension](https://www.postgresql.org/docs/current/citext.html).
@@ -125,6 +128,8 @@ The following links have more information regarding the motivation and design of
125128
* The [original `phx_gen_auth` repo][phx_gen_auth repo] (for Phoenix 1.5 applications) - This is a great resource to see discussions around decisions that have been made in earlier versions of the project.
126129
* [Original pull request on bare Phoenix app][auth PR]
127130
* [Original design spec](https://github.com/dashbitco/mix_phx_gen_auth_demo/blob/auth/README.md)
131+
* [Pull request for migrating LiveView based Phoenix 1.7 `phx.gen.auth` to magic links](https://github.com/SteffenDE/phoenix_gen_auth_magic_link/pull/1)
132+
* [Pull request for migrating controller based Phoenix 1.7 `phx.gen.auth` to magic links](https://github.com/SteffenDE/phoenix_gen_auth_magic_link/pull/2)
128133

129134
[phx_gen_auth repo]: https://github.com/aaronrenner/phx_gen_auth
130135
[auth PR]: https://github.com/dashbitco/mix_phx_gen_auth_demo/pull/1

lib/mix/tasks/phx.gen.auth.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ defmodule Mix.Tasks.Phx.Gen.Auth do
2626
to authentication views without necessarily triggering a new HTTP request
2727
each time (which would result in a full page load).
2828
29-
## Security considerations
29+
## Mixing magic link and password registration
3030
3131
`mix phx.gen.auth` generates email based authentication, which assumes the user who
3232
owns the email address has control over the account. Therefore, it is extremely

priv/templates/phx.gen.auth/context_functions.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@
213213
214214
3. The <%= schema.singular %> has not confirmed their email but a password is set.
215215
This cannot happen in the default implementation but may be the
216-
source of security pitfalls. See the "Security considerations" section of
216+
source of security pitfalls. See the "Mixing magic link and password registration" section of
217217
`mix help phx.gen.auth`.
218218
"""
219219
def login_<%= schema.singular %>_by_magic_link(token) do
@@ -227,7 +227,7 @@
227227
228228
This cannot happen with the default implementation, which indicates that you
229229
might have adapted the code to a different use case. Please make sure to read the
230-
"Security considerations" section of `mix help phx.gen.auth`.
230+
"Mixing magic link and password registration" section of `mix help phx.gen.auth`.
231231
"""
232232

233233
{%<%= inspect schema.alias %>{confirmed_at: nil} = <%= schema.singular %>, _token} ->

0 commit comments

Comments
 (0)