discourse/app/controllers/admin
Osama Sayegh dd6ec65061
FEATURE: Centralized 2FA page (#15377)
2FA support in Discourse was added and grown gradually over the years: we first
added support for TOTP for logins, then we implemented backup codes, and last
but not least, security keys. 2FA usage was initially limited to logging in,
but it has been expanded and we now require 2FA for risky actions such as
adding a new admin to the site.

As a result of this gradual growth of the 2FA system, technical debt has
accumulated to the point where it has become difficult to require 2FA for more
actions. We now have 5 different 2FA UI implementations and each one has to
support all 3 2FA methods (TOTP, backup codes, and security keys) which makes
it difficult to maintain a consistent UX for these different implementations.
Moreover, there is a lot of repeated logic in the server-side code behind these
5 UI implementations which hinders maintainability even more.

This commit is the first step towards repaying the technical debt: it builds a
system that centralizes as much as possible of the 2FA server-side logic and
UI. The 2 main components of this system are:

1. A dedicated page for 2FA with support for all 3 methods.
2. A reusable server-side class that centralizes the 2FA logic (the
`SecondFactor::AuthManager` class).

From a top-level view, the 2FA flow in this new system looks like this:

1. User initiates an action that requires 2FA;

2. Server is aware that 2FA is required for this action, so it redirects the
user to the 2FA page if the user has a 2FA method, otherwise the action is
performed.

3. User submits the 2FA form on the page;

4. Server validates the 2FA and if it's successful, the action is performed and
the user is redirected to the previous page.

A more technically-detailed explanation/documentation of the new system is
available as a comment at the top of the `lib/second_factor/auth_manager.rb`
file. Please note that the details are not set in stone and will likely change
in the future, so please don't use the system in your plugins yet.

Since this is a new system that needs to be tested, we've decided to migrate
only the 2FA for adding a new admin to the new system at this time (in this
commit). Our plan is to gradually migrate the remaining 2FA implementations to
the new system.

For screenshots of the 2FA page, see PR #15377 on GitHub.
2022-02-17 12:12:59 +03:00
..
admin_controller.rb
api_controller.rb FEATURE: Add pagination to API keys page (#14777) 2021-11-09 12:18:23 +02:00
backups_controller.rb FEATURE: Local chunked uppy backup uploads with a new uploader plugin (#14894) 2021-11-23 08:45:42 +10:00
badges_controller.rb FEATURE: Add option to grant badge multiple times to users using Bulk Award (#13571) 2021-07-15 05:53:26 +03:00
color_schemes_controller.rb FEATURE: User selectable color schemes (#10544) 2020-08-28 10:36:52 -04:00
dashboard_controller.rb UX: Changes to new features section in admin dashboard (#12029) 2021-02-10 13:12:04 -05:00
email_controller.rb DEV: Update more Jobs#enqueue calls to use strings (#15823) 2022-02-04 19:58:34 +00:00
email_styles_controller.rb
email_templates_controller.rb Add bad_destination_address template to email_templates_controller (#12102) 2021-02-17 09:57:38 +01:00
embeddable_hosts_controller.rb FIX: use allowlist and blocklist terminology (#10209) 2020-07-27 10:23:54 +10:00
embedding_controller.rb
emojis_controller.rb FIX: Clean up emoji name which is file name (#14980) 2021-11-17 09:20:44 +10:00
groups_controller.rb FEATURE: Experimental support for group membership via google auth (#14835) 2021-12-09 12:30:27 +00:00
impersonate_controller.rb
permalinks_controller.rb
plugins_controller.rb
reports_controller.rb FIX: Only cache reports with exceptions for 1 minute (#11447) 2020-12-09 10:54:41 -06:00
robots_txt_controller.rb
screened_emails_controller.rb
screened_ip_addresses_controller.rb DEV: Do not manually require ip_addr (#15535) 2022-01-11 12:43:00 +02:00
screened_urls_controller.rb
search_logs_controller.rb
site_settings_controller.rb DEV: Remove HTML setting type and sanitization logic. (#14440) 2021-10-04 15:40:35 -03:00
site_texts_controller.rb FIX: Translation overrides from fallback locale didn't work on client 2021-12-17 14:03:35 +01:00
staff_action_logs_controller.rb
themes_controller.rb FIX: Set `auto_update` to false for non-git themes/components (#15157) 2021-12-01 19:58:13 +03:00
user_fields_controller.rb FEATURE: Add user custom fields to user directory (#13238) 2021-06-07 12:34:01 -05:00
users_controller.rb FEATURE: Centralized 2FA page (#15377) 2022-02-17 12:12:59 +03:00
versions_controller.rb
watched_words_controller.rb FEATURE: add staff action logs for watched words (#13574) 2021-06-30 11:22:46 +05:30
web_hooks_controller.rb