<commit_before><?php
/**
 * Plugin Name: E2E Access Token Endpoint
 * Description: REST Endpoint for setting the access token for Site Kit during E2E tests.
 *
 * @package   Google\Site_Kit
 * @copyright 2019 Google LLC
 * @license   https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
 * @link      https://sitekit.withgoogle.com
 */

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' ) ) {
		return;
	}

	register_rest_route(
		REST_Routes::REST_ROOT,
		'e2e/auth/access-token',
		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'] ) )
					)
				);

				return array( 'success' => true, 'token' => $request['token'] );
			}
		)
	);
}, 0 );<commit_msg>e2e: set access token with oauth client<commit_after><?php
/**
 * Plugin Name: E2E Access Token Endpoint
 * Description: REST Endpoint for setting the access token for Site Kit during E2E tests.
 *
 * @package   Google\Site_Kit
 * @copyright 2019 Google LLC
 * @license   https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
 * @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;

add_action( 'rest_api_init', function () {
	if ( ! defined( 'GOOGLESITEKIT_PLUGIN_MAIN_FILE' ) ) {
		return;
	}

	register_rest_route(
		REST_Routes::REST_ROOT,
		'e2e/auth/access-token',
		array(
			'methods'  => WP_REST_Server::EDITABLE,
			'callback' => function ( WP_REST_Request $request ) {
				( new OAuth_Client( new Context( GOOGLESITEKIT_PLUGIN_MAIN_FILE ) ) )
					->set_access_token( $request['token'], HOUR_IN_SECONDS );

				return array( 'success' => true, 'token' => $request['token'] );
			}
		)
	);
}, 0 );
{'fraction_non_alphanumeric': 0.13727359389895138, 'fraction_numerical': 0.011916110581506196, 'mean_word_length': 3.9739336492890995, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 14, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2394069', 'n_tokens_mistral': 826, 'n_tokens_neox': 737, 'n_words': 150}