Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
);

Expand Down Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions projects/plugins/jetpack/sal/class.json-api-site-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Loading