-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a filter to filter the classname used for a provider #546
Conversation
…om the class name.
…allow individual classes to be extended.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good - is there an example we can test where someone has extended the providers?
My only concern with the changes to class instantiation might conflict with someone who has previously set this up.
The best example is the unit test included, and the code included in the PR description.
That's a valid concern, however, it's pretty awkward to extend them at present to the point that this shouldn't break any existing implementations of that. They'd have to be including their own replacement class in the I also can't find any plugins in the directory that extend the core providers: https://wpdirectory.net/search/01GX87VBAWAPCCA0RXEY3HY7G0 |
* Store the two factor login timestamp and provider in the user session. * Create the user session directly attaching data to it, rather than using filters. * Add a method to determine if the current login session is two factored. * Use an anonymous function attached to a callback to set the user session information. * Tests: Add a test that validates that is_current_user_session_two_factor() doesn't return true when the cookie is set from outside of the two-factor handler. * Make is_current_user_session_two_factor() more readable. * Make Two_Factor_Core::login_form_validate_2fa() testable, by not calling exit; * Tests: Add tests that validate that the 2fa status is appropriately set in the user session. * Remove misplaced `@covers` annotation. Co-authored-by: Ian Dunn <ian@iandunn.name> * Correct an @Covers annotation. Co-authored-by: Ian Dunn <ian@iandunn.name> * Update to reflect #546 * Tests: Simplify the cookie management. * Be more explicit about the return value. * Use a static anonymous function, as $this isn't needed. * Simplify the wrapper by allowing _login_form_validate_2fa() to always be exited after calling. * Simplify by passing $provider as a string always. * Update @SInCE tags. --------- Co-authored-by: Ian Dunn <ian@iandunn.name>
What?
This PR allows for the classname of a provider to differ from it's "key" that's used within the application.
This was spurred by an attempt to simply extend a core provider with a custom one to override certain functions (instead of #545 ).
This has resulted in several changes:
Two_Factor_Provider::get_key()
which returns the providers 'key', which defaults to the class name as present.get_instance()
from each individual provider and moving it to the abstractTwo_Factor_Provider
, each provider had a slightly different one, and the usage of__CLASS__
meant children of the provider had to override theget_instance()
method as well.Why?
This allows for users of the plugin to overload a provider with a custom variant of the provider, without having to register an entirely new provider and migrate users over to it.
For example:
How?
By allowing the classname to be filtered, external code can overload core providers with customisations without needing to duplicate the entire provider.
Testing Instructions
npm run test
Screenshots or screencast
Changelog Entry
Added - Better compatibility to allow overloading core Two Factor providers without duplicating the entire provider.