From fc78f2322445b454afecd37d22d144ac0b92c426 Mon Sep 17 00:00:00 2001 From: Evan Mattson Date: Tue, 12 Nov 2019 12:23:33 +0200 Subject: [PATCH] e2e: set access token with oauth client --- tests/e2e/mu-plugins/e2e-rest-access-token.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tests/e2e/mu-plugins/e2e-rest-access-token.php b/tests/e2e/mu-plugins/e2e-rest-access-token.php index 7c695707664..763c5972b4e 100644 --- a/tests/e2e/mu-plugins/e2e-rest-access-token.php +++ b/tests/e2e/mu-plugins/e2e-rest-access-token.php @@ -9,8 +9,9 @@ * @link https://sitekit.withgoogle.com */ +use Google\Site_Kit\Context; +use Google\Site_Kit\Core\Authentication\Clients\OAuth_Client; use Google\Site_Kit\Core\REST_API\REST_Routes; -use Google\Site_Kit\Core\Storage\Data_Encryption; add_action( 'rest_api_init', function () { if ( ! defined( 'GOOGLESITEKIT_PLUGIN_MAIN_FILE' ) ) { @@ -23,13 +24,8 @@ array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => function ( WP_REST_Request $request ) { - update_user_option( - get_current_user_id(), - 'googlesitekit_access_token', - ( new Data_Encryption() )->encrypt( - serialize( array( 'access_token' => $request['token'] ) ) - ) - ); + ( new OAuth_Client( new Context( GOOGLESITEKIT_PLUGIN_MAIN_FILE ) ) ) + ->set_access_token( $request['token'], HOUR_IN_SECONDS ); return array( 'success' => true, 'token' => $request['token'] ); }