Evaluate restoring using a form alter instead of extending UserLoginForm

Created on 4 October 2023, over 1 year ago

Problem/Motivation

In 34a6ca4dd5cce9e375916e50cd5b6956007918ff the code was re-factored from using a form alter to extending the UserLoginForm.

Around 5 years ago the class was marked @internal in ee0f806896ee167f382935bfb40cefec9d4ad1cb

If reverting to a form alter would allow us not to extend core classes it could make the code much more managble and allow us to reduce the maintenance burden.

Steps to reproduce

Review Code

Proposed resolution

Revert to a form alter, or form alter+service configuration.

Remaining tasks

Patch

User interface changes

None

API changes

Impacted classes are @internal.
Remove TfaUserLogin and and only decorate with form alter and validation calls

Data model changes

None

πŸ“Œ Task
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States cmlara

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @cmlara
  • πŸ‡ΊπŸ‡ΈUnited States cmlara

    Uploaded a prototype that was based on some code from last year along with some newer edits of what converting to a form alter could look like.

  • πŸ‡ΊπŸ‡ΈUnited States cmlara

    This ends up being larger than I expected it to be. In hindsight it makes sense as much of the TfaUserLoginForm was our unique code.

    This does however have the advantage that it should remain generally compatible with core, and I believe contrib as well. The largest advantage is we are no longer extending an internal core class.

    The negative is we are tied to the form_state UID value usage.

    Key Design Concepts:

    • While Core and Contrib are attempting to validate passwords in the form Validate stage TfaUserAuth is instructed to not expect a token to be present.
    • Any module that sets the form_state uid value can be combined with TFA.
    • tfaValidateSubmit will check if a token is necessary and if so redirect to the TfaEntryForm.

    All this is backed up by TfaUserSetSubscriber preventing logins occurring during the validation or submit stage for a user who needs to visit the TfaEntryForm.

    If tfaLoginFormPreValidation() is removed by another module users can still log in similar to REST by providing token at the end of the password (failsafe to broken site).

  • πŸ‡ΊπŸ‡ΈUnited States cmlara

    Note: This currently doesn't work with mail_login as TFA needs to know the account name during the pre_auth stage.

    Drupal\user\UserAuthenticationInterface::lookupAccount() could resolve this, although it will not be until D12 that it is fully implemented.

    I would suggest πŸ› Implement Drupal\user\UserAuthenticationInterface Needs review handle that scenario after this issue is merged (unless that issue is merged first).

  • πŸ‡ΊπŸ‡ΈUnited States cmlara

    We likely need a post_update hook to remove/convert the Tfa User Login block.

  • πŸ‡ΊπŸ‡ΈUnited States cmlara

    Created CR: https://www.drupal.org/node/3527521 β†’

    Added admin facing documentation in GitLab Pages format.

  • πŸ‡ΊπŸ‡ΈUnited States cmlara
    • cmlara β†’ committed 80e2aa07 on 2.x
      Issue #3391784 by cmlara: Restore using a form alter instead of...
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024