Skip to content

Commit

Permalink
e2e: set access token with oauth client
Browse files Browse the repository at this point in the history
  • Loading branch information
aaemnnosttv committed Nov 12, 2019
1 parent 20d711b commit fc78f23
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions tests/e2e/mu-plugins/e2e-rest-access-token.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) ) {
Expand All @@ -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'] );
}
Expand Down

0 comments on commit fc78f23

Please sign in to comment.