Create "Email one-time-code" Validation Plugin & related Setup Plugin

Created on 13 December 2017, almost 7 years ago
Updated 7 February 2024, 8 months ago

The goal of this issue is to create a simple OTP validation plugin that leverages the Email send plugin #2930537: Create an Email Send Plugin and test β†’ .

  • The Validation Plugin should leverage the Send Plugin Interface.
  • The Setup Plugin should allow the user to provide additional emails where they can receive the code during validation.
  • During validation, if the user has additional email addresses setup for receiving codes, the plugin should prompt the user to choose which address the code should be sent to. On this prompt, additional email addresses should be obscured so that they are recognizable to the user but not obviously so to others. For example: j****@g***.com
  1. * requires - #2930532: Create the Send Plugin API with a working test β†’
  2. ✨ Create "Email one-time-code" Validation Plugin & related Setup Plugin Closed: outdated
✨ Feature request
Status

Closed: outdated

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States daggerhart

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¦πŸ‡ΊAustralia mingsong πŸ‡¦πŸ‡Ί

    The patch fixes the bug mentioned in #59 and #40.

  • πŸ‡¦πŸ‡ΊAustralia mingsong πŸ‡¦πŸ‡Ί

    Difference between patch #54 and #60.

  • Status changed to Needs review over 1 year ago
  • πŸ‡¦πŸ‡ΊAustralia mingsong πŸ‡¦πŸ‡Ί
  • Status changed to Needs work over 1 year ago
  • πŸ‡΅πŸ‡ΉPortugal jcnventura

    @Mingsong, I know you are using this with 8.x-1.x. This feature will never be added to the 1.x branch. You're free to not want to update it to 2.x, but please don't put it back in "Needs Review" if it is not compatible with 2.x, as I'll simply put it back to "Needs work" until your comments mention that the patch is now ready for 2.x.

  • πŸ‡¦πŸ‡ΊAustralia mingsong πŸ‡¦πŸ‡Ί

    @JoΓ£o Ventura, thanks for the heads up. We will need the 2.x at some point in the future, as 8.x-1.x will not be supported after Drupal 9.

    No problem. Understand that 1.x is bug fixing only.

    I can help this issue for 2.x branch as well. But at this stage, 2.x branch is just not stable enough to integrate this plugin.

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

    @Mingsong thank you for the patch tfa-2930541-60.patch. However, I still see the bug mentioned in #40 and #59. I am on 8.x-1.0. Here are the steps.

    1. Login on a new browser session.
    2. On TFA page, enter the authentication code from the email, select "Remember this browser for 30 days?" and verify.
    3. Logout from the website.
    4. Login again in the same browser session.
    5. The user is logged in without TFA page and shows the message "You have logged in on a trusted browser.".
    6. However, the authentication code for the 2nd login is sent to the email.

    Thanks for looking into this.

  • πŸ‡¦πŸ‡ΊAustralia mingsong πŸ‡¦πŸ‡Ί

    Thanks @Naveen for testing the patch.

    As in our use cases, the 'Trusted browser" is not allowed. So we didn't test this scenario.

    The problem comes from the fix for bug mentioned in #47.

    The easy fix for this bug is to change the button from 'Resend' to 'Send', and the user has to click the button at least once.

    In this way, we don't modify the logic and login process of TFA, otherwise it will require a lots of testing and might be not work with other custom plugins provided by another modules.

    Here is the new patch.

  • πŸ‡¦πŸ‡ΊAustralia mingsong πŸ‡¦πŸ‡Ί

    Changes between patch #60 and #66.

  • πŸ‡¨πŸ‡¦Canada minoroffense Ottawa, Canada

    Here's an updated plugin that sends the user the email when the form loads, tracks the send in the state expire system and posts a message to the user letting them know what's going on.

  • πŸ‡¨πŸ‡¦Canada minoroffense Ottawa, Canada

    Sorry, I messed up the previous patch.

    Here's a corrected one without parts missing. I also added a cleanup on the state var once the code is validated (in case the user logs in / out quickly before the code expires).

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    19 pass
  • πŸ‡ΊπŸ‡ΈUnited States wildcats369

    @minorOffense, thanks for providing the patch. I tested it and found an issue in the following scenario.

    Here are the steps.

    1. Login on a new browser session.
    2. On TFA page, enter the authentication code from the email, DON'T select "Remember this browser for 30 days?" and verify.
    3. Logout from the website.
    4. Login again in the same browser session.
    5. The user is prompted for the authentication code on the TFA page, but the email with the code is not automatically sent. I had to click "Send" to get the email.

    It's working fine for other scenarios when selecting to remember the browser for 30 days.

    Thanks for looking into this.

  • Status changed to Active over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States l-laziz
  • Status changed to Needs work over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States greggles Denver, Colorado, USA

    I think this is still a task (really feature) that needs work.

    If you disagree please explain why as you change the category and status.

  • πŸ‡¦πŸ‡ΊAustralia mingsong πŸ‡¦πŸ‡Ί

    Patch for 2.x branch.

    I will work on the test for the new feature.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 8
    last update over 1 year ago
    21 pass
  • πŸ‡¦πŸ‡ΊAustralia mingsong πŸ‡¦πŸ‡Ί

    Patch #73 has some bugs.
    Here is the new patch without having PHPUnit test.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 8
    last update over 1 year ago
    21 pass
  • πŸ‡¦πŸ‡ΊAustralia mingsong πŸ‡¦πŸ‡Ί

    The patch for 2.x branch with a new test.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 8
    last update over 1 year ago
    22 pass
  • πŸ‡¦πŸ‡ΊAustralia mingsong πŸ‡¦πŸ‡Ί

    Patch #73 and #74 is out of date.

  • Status changed to Needs review over 1 year ago
  • πŸ‡¦πŸ‡ΊAustralia mingsong πŸ‡¦πŸ‡Ί

    Since the patch for 2.x is provided, I put this issue to 'Needs review'.

    Please feel free to correct me if I was wrong.

  • πŸ‡΅πŸ‡ΉPortugal jcnventura

    Thanks for this Mingsong. I'll try to test this soon(ish). Would be good to see some of the others in this thread also test this.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    22 pass
  • πŸ‡ΊπŸ‡ΈUnited States l-laziz

    Tested patch #75. With this new behavior when code is sent only after clicking "Send" button, the hint text under the code box
    "The authentication code has been sent to your registered email. Check your email and enter the code."
    is not correct anymore, since the code is not being sent initially.
    I would suggest to change it to Status message area instead of embedded in the form as of now. Attaching a patch with this change.

  • πŸ‡¦πŸ‡ΊAustralia mingsong πŸ‡¦πŸ‡Ί

    Thanks @Laziz,

    FYI, the changes between patch #75 and #79 is

    diff --git a/src/Plugin/Tfa/TfaEmailCode.php b/src/Plugin/Tfa/TfaEmailCode.php
    index 6e0e0cd..52e5b26 100644
    --- a/src/Plugin/Tfa/TfaEmailCode.php
    +++ b/src/Plugin/Tfa/TfaEmailCode.php
    @@ -217,6 +217,9 @@ class TfaEmailCode extends TfaBasePlugin implements TfaValidationInterface, TfaS
             '@email' => $this->recipient->getEmail(),
           ]));
         }
    +    else {
    +        \Drupal::messenger()->addMessage(t('The authentication code has been sent to your registered email. Check your email and enter the code.'));
    +    }
     
         $this->isSent = TRUE;
       }
    @@ -228,9 +231,9 @@ class TfaEmailCode extends TfaBasePlugin implements TfaValidationInterface, TfaS
     
         $form['code'] = [
           '#type' => 'textfield',
    -      '#title' => $this->t('Enter the received code'),
    +      '#title' => $this->t('Authentication code'),
           '#required' => TRUE,
    -      '#description' => $this->t('The authentication code has been sent to your registered email. Check your email and enter the code.'),
    +      '#description' => $this->t('Enter the code received'),
           '#attributes' => ['autocomplete' => 'off'],
         ];
         $form['actions']['#type'] = 'actions';
    
  • πŸ‡¦πŸ‡ΊAustralia mingsong πŸ‡¦πŸ‡Ί

    Refresh the patch for 8.x-1.1.0.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 8
    last update about 1 year ago
    21 pass
  • πŸ‡ΊπŸ‡ΈUnited States cmlara

    Hiding remaining 1.x patches as #46 converted this to a 2.x issue.

    There is no need to upload new 1.x patches until the 2.x patch is accepted and the previous decision of this being a 2.x only issue has been reverted.

    If you are uploading 1.x patches here that are intended for used in your own local deployment please keep those patches on your own server to avoid unnecessary posts into the issue history.

  • πŸ‡¦πŸ‡ΊAustralia mingsong πŸ‡¦πŸ‡Ί

    Hi @Conrad,

    I understand this issue has been ported to 2.x. However we can't use TFA 2.x for our production sites until a stable release which is covered by Drupal security advisory.

    The patch uploaded here for 8.x-1.1 is not for testing purpose, but for production patching via composer.

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

    It is generally recommended to not depend on production patches being hosted on D.O.. Patches should instead be kept somewhere 'local'.

    I would also recommend sites not use work in progress patches in production. The patches in this issue may change at any time, security faults may be disclosed without any resolution, and compatibility may break in any new iteration.

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

    With the most recent TFA update (8.x-1.4 Stable release, released 29 November 2023), our users are getting multiple emails from the email plugin, and the codes don't seem to work. The patch seemed to be applied. Is anyone else having this issue?

  • πŸ‡¦πŸ‡ΊAustralia mingsong πŸ‡¦πŸ‡Ί

    It has been 6 years.

    I think it is time to have a contribute module for this feature.

    https://www.drupal.org/project/tfa_email_otp β†’

  • Status changed to Postponed 10 months ago
  • πŸ‡ΊπŸ‡ΈUnited States cmlara

    Seems fair to move this to contrib.

    I will leave this issue open until a release is made and than close as outdated.

    Glancing at https://www.drupal.org/project/tfa/ecosystem β†’ I don't see the module listed. I would encourage updating the module so that it appears as part of the TFA ecosystem so others can more easily discover it.

  • πŸ‡¦πŸ‡ΊAustralia mingsong πŸ‡¦πŸ‡Ί

    Thanks @Conrad.

    I was confused by the module name. There are multiple module ecosystems call 'Two Factor Authentication'.

    I think I got it right now.

  • πŸ‡¦πŸ‡ΊAustralia mingsong πŸ‡¦πŸ‡Ί

    @Conrad, first release is out. You can close this issue now if you like.

  • Status changed to Closed: outdated 9 months ago
  • πŸ‡ΊπŸ‡ΈUnited States cmlara

    Thank you for the update @Mingsong!

    Looks like good progress in bringing this forward as a community module.

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

    @MingSong Well done! I was looking for an email OTP to replace the functionality of tfa_basic that we were using on D7.

    Installed your plugin module to a site using 1.5 of TFA and it works a treat. Thank you!

Production build 0.71.5 2024