From ea482093041b765419b312378c896e01d1a00cf0 Mon Sep 17 00:00:00 2001 From: Bryan Davis Date: Sun, 2 Aug 2020 16:57:49 -0600 Subject: [PATCH] Add application-passwords plugin Add George Stephanis' Application Passwords plugin to allow authenticating to the WordPress API via alternate tokens. We also add custom filter handler for 'two_factor_user_api_login_enable' which disables 2FA prompting when auth is done using an application password. Bug: T250873 --- .gitmodules | 3 +++ client-mu-plugins/plugin-loader.php | 15 +++++++++++++-- plugins/application-passwords | 1 + 3 files changed, 17 insertions(+), 2 deletions(-) create mode 160000 plugins/application-passwords diff --git a/.gitmodules b/.gitmodules index 79ef618..62e50a6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [submodule "plugins/disable-emojis"] path = plugins/disable-emojis url = https://github.com/ryanhellyer/disable-emojis +[submodule "plugins/application-passwords"] + path = plugins/application-passwords + url = https://github.com/WordPress/application-passwords.git diff --git a/client-mu-plugins/plugin-loader.php b/client-mu-plugins/plugin-loader.php index a5f3218..8dbf384 100644 --- a/client-mu-plugins/plugin-loader.php +++ b/client-mu-plugins/plugin-loader.php @@ -2,11 +2,11 @@ /* * We recommend all plugins for your site are * loaded in code, either from a file like this - * one or from your theme (if the plugins are + * one or from your theme (if the plugins are * specific to your theme and do not need to be * loaded as early as this in the WordPress boot * sequence. - * + * * @see https://vip.wordpress.com/documentation/vip-go/understanding-your-vip-go-codebase/ */ @@ -42,3 +42,14 @@ function cmu_always_multi_author( $transient ) { return true; } add_filter( 'pre_transient_is_multi_author', 'cmu_always_multi_author' ); + +/** + * Allow api login using application-passwords even when account normally + * requires 2FA authentication. + */ +add_filter( 'two_factor_user_api_login_enable', function( $enable ) { + if ( did_action( 'application_password_did_authenticate' ) ) { + return true; + } + return $enable; +} ); diff --git a/plugins/application-passwords b/plugins/application-passwords new file mode 160000 index 0000000..0b89900 --- /dev/null +++ b/plugins/application-passwords @@ -0,0 +1 @@ +Subproject commit 0b899005796c270e9fde79af1c92f0430de3da14