diff --git a/projects/plugins/jetpack/changelog/add-site-option-jetpack-sso-require-two-step b/projects/plugins/jetpack/changelog/add-site-option-jetpack-sso-require-two-step new file mode 100644 index 000000000000..361423984d11 --- /dev/null +++ b/projects/plugins/jetpack/changelog/add-site-option-jetpack-sso-require-two-step @@ -0,0 +1,4 @@ +Significance: minor +Type: enhancement + +Sites API: return the "Require two-step authentication" SSO setting as the `jetpack_sso_require_two_step` site option. diff --git a/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-get-site-endpoint.php b/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-get-site-endpoint.php index d47666a50662..c0d807d2ec08 100644 --- a/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-get-site-endpoint.php +++ b/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-get-site-endpoint.php @@ -245,6 +245,7 @@ class WPCOM_JSON_API_GET_Site_Endpoint extends WPCOM_JSON_API_Endpoint { 'wpcom_admin_interface', 'wpcom_classic_early_release', 'jetpack_recovery_mode_status', + 'jetpack_sso_require_two_step', 'apm_enabled', 'wpcom_ai_launchpad_enabled', 'wpcom_ai_launchpad_dismissed', @@ -321,6 +322,7 @@ class WPCOM_JSON_API_GET_Site_Endpoint extends WPCOM_JSON_API_Endpoint { 'wpcom_admin_interface', 'wpcom_classic_early_release', 'jetpack_recovery_mode_status', + 'jetpack_sso_require_two_step', 'apm_enabled', ); @@ -1026,6 +1028,9 @@ protected function render_option_keys( &$options_response_keys ) { case 'jetpack_recovery_mode_status': $options[ $key ] = $site->get_jetpack_recovery_mode_status(); break; + case 'jetpack_sso_require_two_step': + $options[ $key ] = $site->get_jetpack_sso_require_two_step(); + break; case 'apm_enabled': $options[ $key ] = $site->get_apm_enabled(); break; diff --git a/projects/plugins/jetpack/sal/class.json-api-site-base.php b/projects/plugins/jetpack/sal/class.json-api-site-base.php index 3e425d45cbe4..ad0b64730945 100644 --- a/projects/plugins/jetpack/sal/class.json-api-site-base.php +++ b/projects/plugins/jetpack/sal/class.json-api-site-base.php @@ -1894,4 +1894,14 @@ public function get_jetpack_recovery_mode_status() { $status = get_option( 'jetpack_recovery_mode_status' ); return is_array( $status ) ? $status : null; } + + /** + * Whether WordPress.com accounts must have two-step authentication to log in through SSO. + * + * @return bool + */ + public function get_jetpack_sso_require_two_step() { + /** This filter is documented in projects/packages/connection/src/sso/class-helpers.php */ + return (bool) apply_filters( 'jetpack_sso_require_two_step', get_option( 'jetpack_sso_require_two_step', false ) ); + } } diff --git a/projects/plugins/jetpack/tests/php/json-api/Jetpack_Site_Json_Api_Endpoints_Test.php b/projects/plugins/jetpack/tests/php/json-api/Jetpack_Site_Json_Api_Endpoints_Test.php index f9a4516ed4b7..333c367b3a2c 100644 --- a/projects/plugins/jetpack/tests/php/json-api/Jetpack_Site_Json_Api_Endpoints_Test.php +++ b/projects/plugins/jetpack/tests/php/json-api/Jetpack_Site_Json_Api_Endpoints_Test.php @@ -70,6 +70,40 @@ public function test_get_site() { $this->assertArrayHasKey( 'jetpack_connection_active_plugins', $options ); } + /** + * The `jetpack_sso_require_two_step` site option reports what SSO enforces: the saved + * setting, or `true` when the `jetpack_sso_require_two_step` filter forces it. + */ + public function test_get_site_jetpack_sso_require_two_step_option() { + global $blog_id; + + $editor = self::factory()->user->create_and_get( + array( + 'role' => 'editor', + ) + ); + + wp_set_current_user( $editor->ID ); + + $endpoint = $this->create_get_site_endpoint(); + + $response = $endpoint->callback( '', $blog_id ); + $this->assertFalse( ( (array) $response['options'] )['jetpack_sso_require_two_step'] ); + + update_option( 'jetpack_sso_require_two_step', '1' ); + + $response = $endpoint->callback( '', $blog_id ); + $this->assertTrue( ( (array) $response['options'] )['jetpack_sso_require_two_step'] ); + + delete_option( 'jetpack_sso_require_two_step' ); + add_filter( 'jetpack_sso_require_two_step', '__return_true' ); + + $response = $endpoint->callback( '', $blog_id ); + $this->assertTrue( ( (array) $response['options'] )['jetpack_sso_require_two_step'] ); + + remove_filter( 'jetpack_sso_require_two_step', '__return_true' ); + } + /** * Test that trial flags are returned for sites that have them. *