Skip to content

Commit

Permalink
Revert "Move to the generic authenticate filter since there we reliab…
Browse files Browse the repository at this point in the history
…ly know the user state"

This reverts commit 0e1b244.
  • Loading branch information
kasparsd committed Jan 10, 2025
1 parent 0e1b244 commit e7f1ad6
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions class-two-factor-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -682,17 +682,11 @@ public static function destroy_current_session_for_user( $user ) {
* @return WP_User|WP_Error
*/
public static function filter_authenticate( $user ) {
if ( $user instanceof WP_User && self::is_user_using_two_factor( $user->ID ) ) {
// Trigger the second-factor flow if the password was correct.
add_action( 'wp_login', array( __CLASS__, 'wp_login' ), 10, 2 );

// Disable the XML-RPC and REST API for users with two-factor enabled.
if ( self::is_api_request() && ! self::is_user_api_login_enabled( $user->ID ) ) {
return new WP_Error(
'invalid_application_credentials',
__( 'Error: API login for user disabled.', 'two-factor' )
);
}
if ( $user instanceof WP_User && self::is_api_request() && self::is_user_using_two_factor( $user->ID ) && ! self::is_user_api_login_enabled( $user->ID ) ) {
return new WP_Error(
'invalid_application_credentials',
__( 'Error: API login for user disabled.', 'two-factor' )
);
}

return $user;
Expand All @@ -715,6 +709,7 @@ public static function filter_authenticate_block_cookies( $user ) {
* rather than through an unsupported 3rd-party login process which this plugin doesn't support.
*/
if ( $user instanceof WP_User && self::is_user_using_two_factor( $user->ID ) && did_action( 'login_init' ) ) {
add_action( 'wp_login', array( __CLASS__, 'wp_login' ), 10, 2 );
add_filter( 'send_auth_cookies', '__return_false', PHP_INT_MAX );
}

Expand Down

0 comments on commit e7f1ad6

Please sign in to comment.