Currently when defining a Validation plugin the TFA module requires you to also write a Setup plugin. Additionally, the setup plugin must have a specific ID as implied by the TFA source.
For example in BasicOverview.php, the module attempts to load a Setup plugin for every Validation plugin with the following approach: $plugin . '_setup'. This pattern of a Validation's plugin ID concatenated with '_setup' is repeated a number of times to load the setup plugin.
One problem with this approach is that it forces every Validation plugin to implement a Setup plugin with the very specific ID. I believe a more flexible approach would be to be to make the Setup plugin ID an optional part of the Validation plugin's annotation.
For example:
/**
* TOTP validation class for performing TOTP validation.
*
* @TfaValidation(
* id = "tfa_totp",
* label = @Translation("TFA Time-based OTP(TOTP)"),
* description = @Translation("TFA Totp Validation Plugin"),
* setupPluginId = "tfa_totp_setup",
* )
*/
And I believe this annotation should be optional because I can imagine cases where a plugin does not require additional setup by the end user. I'm not saying I have a great example in mind, just that I can imagine someone else smarter than me coming up with valid reasons not to have a user-setup form for a plugin.
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | 2925066-18.patch | 17.94 KB | jcnventura |
| #16 | 2925066-16-interdiff.txt | 2.85 KB | jonas139 |
| #16 | 2925066-16.patch | 18.82 KB | jonas139 |
| #15 | interdiff.txt | 13.23 KB | daggerhart |
| #15 | 2925066-15.patch | 18.12 KB | daggerhart |
Comments
Comment #2
daggerhart commentedComment #3
daggerhart commentedComment #4
daggerhart commentedAttach patch defines the new annotation property for Login, Send, and Validation plugins. It also refactors all previous usage of
$plugin_id . '_setup'to checking for and using this new annotation property.Comment #5
jeroentComment #6
jeroentPatch no longer applies.
Comment #7
jeroentCreated reroll.
Comment #9
jeroentComment #11
jeroentFixed failing test. Added SetupPluginId in TfaTestValidationPlugin.
Comment #12
screon commentedSomething breaks after applying the patch:
You are expecting an array but in the function calls in buildForm() the $plugin argument is still a string (coming from $configuration).
This results in the following error when browsing to /user/UID/security/tfa:
TypeError: Argument 1 passed to Drupal\tfa\Form\BasicOverview::tfaPluginSetupFormOverview() must be of the type array, string given, called in /var/www/bricks/modules/custom/tfa/src/Form/BasicOverview.php on line 149 in Drupal\tfa\Form\BasicOverview->tfaPluginSetupFormOverview() (regel 205 van /var/www/bricks/modules/custom/tfa/src/Form/BasicOverview.php)Comment #13
screon commentedFixed the above mentioned issue.
Comment #14
daggerhart commentedPatch seems to still apply, but with some fudging. Re-rolling for some additional review.
Comment #15
daggerhart commentedHere is a patch where I've added some backwards compatibility methods to our plugin managers. These methods basically just add the old implicit setupPluginId to any plugin that does not have one explicitly set. This should remove our need to coordinate this change with every existing contrib module that implement TFA plugins.
I've reviewed changes a bit and did a lot of manual testing. If someone else could give this a glance, I think we can get this committed without much risk.
Comment #16
jonas139 commentedI reviewed the patch and all seems correct.
I only made some small esthetic changes (typos and such) to the patch so for me it's good to go.
Comment #17
jcnventuraComment #18
jcnventuraRe-roll of #16. No interdiff as the patch no longer applies.
Comment #20
jcnventura