Brak opisu

class-wc-rest-authentication.php 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. <?php
  2. /**
  3. * REST API Authentication
  4. *
  5. * @package WooCommerce\RestApi
  6. * @since 2.6.0
  7. */
  8. defined( 'ABSPATH' ) || exit;
  9. /**
  10. * REST API authentication class.
  11. */
  12. class WC_REST_Authentication {
  13. /**
  14. * Authentication error.
  15. *
  16. * @var WP_Error
  17. */
  18. protected $error = null;
  19. /**
  20. * Logged in user data.
  21. *
  22. * @var stdClass
  23. */
  24. protected $user = null;
  25. /**
  26. * Current auth method.
  27. *
  28. * @var string
  29. */
  30. protected $auth_method = '';
  31. /**
  32. * Initialize authentication actions.
  33. */
  34. public function __construct() {
  35. add_filter( 'determine_current_user', array( $this, 'authenticate' ), 15 );
  36. add_filter( 'rest_authentication_errors', array( $this, 'authentication_fallback' ) );
  37. add_filter( 'rest_authentication_errors', array( $this, 'check_authentication_error' ), 15 );
  38. add_filter( 'rest_post_dispatch', array( $this, 'send_unauthorized_headers' ), 50 );
  39. add_filter( 'rest_pre_dispatch', array( $this, 'check_user_permissions' ), 10, 3 );
  40. }
  41. /**
  42. * Check if is request to our REST API.
  43. *
  44. * @return bool
  45. */
  46. protected function is_request_to_rest_api() {
  47. if ( empty( $_SERVER['REQUEST_URI'] ) ) {
  48. return false;
  49. }
  50. $rest_prefix = trailingslashit( rest_get_url_prefix() );
  51. $request_uri = esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) );
  52. // Check if the request is to the WC API endpoints.
  53. $woocommerce = ( false !== strpos( $request_uri, $rest_prefix . 'wc/' ) );
  54. // Allow third party plugins use our authentication methods.
  55. $third_party = ( false !== strpos( $request_uri, $rest_prefix . 'wc-' ) );
  56. return apply_filters( 'woocommerce_rest_is_request_to_rest_api', $woocommerce || $third_party );
  57. }
  58. /**
  59. * Authenticate user.
  60. *
  61. * @param int|false $user_id User ID if one has been determined, false otherwise.
  62. * @return int|false
  63. */
  64. public function authenticate( $user_id ) {
  65. // Do not authenticate twice and check if is a request to our endpoint in the WP REST API.
  66. if ( ! empty( $user_id ) || ! $this->is_request_to_rest_api() ) {
  67. return $user_id;
  68. }
  69. if ( is_ssl() ) {
  70. $user_id = $this->perform_basic_authentication();
  71. }
  72. if ( $user_id ) {
  73. return $user_id;
  74. }
  75. return $this->perform_oauth_authentication();
  76. }
  77. /**
  78. * Authenticate the user if authentication wasn't performed during the
  79. * determine_current_user action.
  80. *
  81. * Necessary in cases where wp_get_current_user() is called before WooCommerce is loaded.
  82. *
  83. * @see https://github.com/woocommerce/woocommerce/issues/26847
  84. *
  85. * @param WP_Error|null|bool $error Error data.
  86. * @return WP_Error|null|bool
  87. */
  88. public function authentication_fallback( $error ) {
  89. if ( ! empty( $error ) ) {
  90. // Another plugin has already declared a failure.
  91. return $error;
  92. }
  93. if ( empty( $this->error ) && empty( $this->auth_method ) && empty( $this->user ) && 0 === get_current_user_id() ) {
  94. // Authentication hasn't occurred during `determine_current_user`, so check auth.
  95. $user_id = $this->authenticate( false );
  96. if ( $user_id ) {
  97. wp_set_current_user( $user_id );
  98. return true;
  99. }
  100. }
  101. return $error;
  102. }
  103. /**
  104. * Check for authentication error.
  105. *
  106. * @param WP_Error|null|bool $error Error data.
  107. * @return WP_Error|null|bool
  108. */
  109. public function check_authentication_error( $error ) {
  110. // Pass through other errors.
  111. if ( ! empty( $error ) ) {
  112. return $error;
  113. }
  114. return $this->get_error();
  115. }
  116. /**
  117. * Set authentication error.
  118. *
  119. * @param WP_Error $error Authentication error data.
  120. */
  121. protected function set_error( $error ) {
  122. // Reset user.
  123. $this->user = null;
  124. $this->error = $error;
  125. }
  126. /**
  127. * Get authentication error.
  128. *
  129. * @return WP_Error|null.
  130. */
  131. protected function get_error() {
  132. return $this->error;
  133. }
  134. /**
  135. * Basic Authentication.
  136. *
  137. * SSL-encrypted requests are not subject to sniffing or man-in-the-middle
  138. * attacks, so the request can be authenticated by simply looking up the user
  139. * associated with the given consumer key and confirming the consumer secret
  140. * provided is valid.
  141. *
  142. * @return int|bool
  143. */
  144. private function perform_basic_authentication() {
  145. $this->auth_method = 'basic_auth';
  146. $consumer_key = '';
  147. $consumer_secret = '';
  148. // If the $_GET parameters are present, use those first.
  149. if ( ! empty( $_GET['consumer_key'] ) && ! empty( $_GET['consumer_secret'] ) ) { // WPCS: CSRF ok.
  150. $consumer_key = $_GET['consumer_key']; // WPCS: CSRF ok, sanitization ok.
  151. $consumer_secret = $_GET['consumer_secret']; // WPCS: CSRF ok, sanitization ok.
  152. }
  153. // If the above is not present, we will do full basic auth.
  154. if ( ! $consumer_key && ! empty( $_SERVER['PHP_AUTH_USER'] ) && ! empty( $_SERVER['PHP_AUTH_PW'] ) ) {
  155. $consumer_key = $_SERVER['PHP_AUTH_USER']; // WPCS: CSRF ok, sanitization ok.
  156. $consumer_secret = $_SERVER['PHP_AUTH_PW']; // WPCS: CSRF ok, sanitization ok.
  157. }
  158. // Stop if don't have any key.
  159. if ( ! $consumer_key || ! $consumer_secret ) {
  160. return false;
  161. }
  162. // Get user data.
  163. $this->user = $this->get_user_data_by_consumer_key( $consumer_key );
  164. if ( empty( $this->user ) ) {
  165. return false;
  166. }
  167. // Validate user secret.
  168. if ( ! hash_equals( $this->user->consumer_secret, $consumer_secret ) ) { // @codingStandardsIgnoreLine
  169. $this->set_error( new WP_Error( 'woocommerce_rest_authentication_error', __( 'Consumer secret is invalid.', 'woocommerce' ), array( 'status' => 401 ) ) );
  170. return false;
  171. }
  172. return $this->user->user_id;
  173. }
  174. /**
  175. * Parse the Authorization header into parameters.
  176. *
  177. * @since 3.0.0
  178. *
  179. * @param string $header Authorization header value (not including "Authorization: " prefix).
  180. *
  181. * @return array Map of parameter values.
  182. */
  183. public function parse_header( $header ) {
  184. if ( 'OAuth ' !== substr( $header, 0, 6 ) ) {
  185. return array();
  186. }
  187. // From OAuth PHP library, used under MIT license.
  188. $params = array();
  189. if ( preg_match_all( '/(oauth_[a-z_-]*)=(:?"([^"]*)"|([^,]*))/', $header, $matches ) ) {
  190. foreach ( $matches[1] as $i => $h ) {
  191. $params[ $h ] = urldecode( empty( $matches[3][ $i ] ) ? $matches[4][ $i ] : $matches[3][ $i ] );
  192. }
  193. if ( isset( $params['realm'] ) ) {
  194. unset( $params['realm'] );
  195. }
  196. }
  197. return $params;
  198. }
  199. /**
  200. * Get the authorization header.
  201. *
  202. * On certain systems and configurations, the Authorization header will be
  203. * stripped out by the server or PHP. Typically this is then used to
  204. * generate `PHP_AUTH_USER`/`PHP_AUTH_PASS` but not passed on. We use
  205. * `getallheaders` here to try and grab it out instead.
  206. *
  207. * @since 3.0.0
  208. *
  209. * @return string Authorization header if set.
  210. */
  211. public function get_authorization_header() {
  212. if ( ! empty( $_SERVER['HTTP_AUTHORIZATION'] ) ) {
  213. return wp_unslash( $_SERVER['HTTP_AUTHORIZATION'] ); // WPCS: sanitization ok.
  214. }
  215. if ( function_exists( 'getallheaders' ) ) {
  216. $headers = getallheaders();
  217. // Check for the authoization header case-insensitively.
  218. foreach ( $headers as $key => $value ) {
  219. if ( 'authorization' === strtolower( $key ) ) {
  220. return $value;
  221. }
  222. }
  223. }
  224. return '';
  225. }
  226. /**
  227. * Get oAuth parameters from $_GET, $_POST or request header.
  228. *
  229. * @since 3.0.0
  230. *
  231. * @return array|WP_Error
  232. */
  233. public function get_oauth_parameters() {
  234. $params = array_merge( $_GET, $_POST ); // WPCS: CSRF ok.
  235. $params = wp_unslash( $params );
  236. $header = $this->get_authorization_header();
  237. if ( ! empty( $header ) ) {
  238. // Trim leading spaces.
  239. $header = trim( $header );
  240. $header_params = $this->parse_header( $header );
  241. if ( ! empty( $header_params ) ) {
  242. $params = array_merge( $params, $header_params );
  243. }
  244. }
  245. $param_names = array(
  246. 'oauth_consumer_key',
  247. 'oauth_timestamp',
  248. 'oauth_nonce',
  249. 'oauth_signature',
  250. 'oauth_signature_method',
  251. );
  252. $errors = array();
  253. $have_one = false;
  254. // Check for required OAuth parameters.
  255. foreach ( $param_names as $param_name ) {
  256. if ( empty( $params[ $param_name ] ) ) {
  257. $errors[] = $param_name;
  258. } else {
  259. $have_one = true;
  260. }
  261. }
  262. // All keys are missing, so we're probably not even trying to use OAuth.
  263. if ( ! $have_one ) {
  264. return array();
  265. }
  266. // If we have at least one supplied piece of data, and we have an error,
  267. // then it's a failed authentication.
  268. if ( ! empty( $errors ) ) {
  269. $message = sprintf(
  270. /* translators: %s: amount of errors */
  271. _n( 'Missing OAuth parameter %s', 'Missing OAuth parameters %s', count( $errors ), 'woocommerce' ),
  272. implode( ', ', $errors )
  273. );
  274. $this->set_error( new WP_Error( 'woocommerce_rest_authentication_missing_parameter', $message, array( 'status' => 401 ) ) );
  275. return array();
  276. }
  277. return $params;
  278. }
  279. /**
  280. * Perform OAuth 1.0a "one-legged" (http://oauthbible.com/#oauth-10a-one-legged) authentication for non-SSL requests.
  281. *
  282. * This is required so API credentials cannot be sniffed or intercepted when making API requests over plain HTTP.
  283. *
  284. * This follows the spec for simple OAuth 1.0a authentication (RFC 5849) as closely as possible, with two exceptions:
  285. *
  286. * 1) There is no token associated with request/responses, only consumer keys/secrets are used.
  287. *
  288. * 2) The OAuth parameters are included as part of the request query string instead of part of the Authorization header,
  289. * This is because there is no cross-OS function within PHP to get the raw Authorization header.
  290. *
  291. * @link http://tools.ietf.org/html/rfc5849 for the full spec.
  292. *
  293. * @return int|bool
  294. */
  295. private function perform_oauth_authentication() {
  296. $this->auth_method = 'oauth1';
  297. $params = $this->get_oauth_parameters();
  298. if ( empty( $params ) ) {
  299. return false;
  300. }
  301. // Fetch WP user by consumer key.
  302. $this->user = $this->get_user_data_by_consumer_key( $params['oauth_consumer_key'] );
  303. if ( empty( $this->user ) ) {
  304. $this->set_error( new WP_Error( 'woocommerce_rest_authentication_error', __( 'Consumer key is invalid.', 'woocommerce' ), array( 'status' => 401 ) ) );
  305. return false;
  306. }
  307. // Perform OAuth validation.
  308. $signature = $this->check_oauth_signature( $this->user, $params );
  309. if ( is_wp_error( $signature ) ) {
  310. $this->set_error( $signature );
  311. return false;
  312. }
  313. $timestamp_and_nonce = $this->check_oauth_timestamp_and_nonce( $this->user, $params['oauth_timestamp'], $params['oauth_nonce'] );
  314. if ( is_wp_error( $timestamp_and_nonce ) ) {
  315. $this->set_error( $timestamp_and_nonce );
  316. return false;
  317. }
  318. return $this->user->user_id;
  319. }
  320. /**
  321. * Verify that the consumer-provided request signature matches our generated signature,
  322. * this ensures the consumer has a valid key/secret.
  323. *
  324. * @param stdClass $user User data.
  325. * @param array $params The request parameters.
  326. * @return true|WP_Error
  327. */
  328. private function check_oauth_signature( $user, $params ) {
  329. $http_method = isset( $_SERVER['REQUEST_METHOD'] ) ? strtoupper( $_SERVER['REQUEST_METHOD'] ) : ''; // WPCS: sanitization ok.
  330. $request_path = isset( $_SERVER['REQUEST_URI'] ) ? wp_parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ) : ''; // WPCS: sanitization ok.
  331. $wp_base = get_home_url( null, '/', 'relative' );
  332. if ( substr( $request_path, 0, strlen( $wp_base ) ) === $wp_base ) {
  333. $request_path = substr( $request_path, strlen( $wp_base ) );
  334. }
  335. $base_request_uri = rawurlencode( get_home_url( null, $request_path, is_ssl() ? 'https' : 'http' ) );
  336. // Get the signature provided by the consumer and remove it from the parameters prior to checking the signature.
  337. $consumer_signature = rawurldecode( str_replace( ' ', '+', $params['oauth_signature'] ) );
  338. unset( $params['oauth_signature'] );
  339. // Sort parameters.
  340. if ( ! uksort( $params, 'strcmp' ) ) {
  341. return new WP_Error( 'woocommerce_rest_authentication_error', __( 'Invalid signature - failed to sort parameters.', 'woocommerce' ), array( 'status' => 401 ) );
  342. }
  343. // Normalize parameter key/values.
  344. $params = $this->normalize_parameters( $params );
  345. $query_string = implode( '%26', $this->join_with_equals_sign( $params ) ); // Join with ampersand.
  346. $string_to_sign = $http_method . '&' . $base_request_uri . '&' . $query_string;
  347. if ( 'HMAC-SHA1' !== $params['oauth_signature_method'] && 'HMAC-SHA256' !== $params['oauth_signature_method'] ) {
  348. return new WP_Error( 'woocommerce_rest_authentication_error', __( 'Invalid signature - signature method is invalid.', 'woocommerce' ), array( 'status' => 401 ) );
  349. }
  350. $hash_algorithm = strtolower( str_replace( 'HMAC-', '', $params['oauth_signature_method'] ) );
  351. $secret = $user->consumer_secret . '&';
  352. $signature = base64_encode( hash_hmac( $hash_algorithm, $string_to_sign, $secret, true ) );
  353. if ( ! hash_equals( $signature, $consumer_signature ) ) { // @codingStandardsIgnoreLine
  354. return new WP_Error( 'woocommerce_rest_authentication_error', __( 'Invalid signature - provided signature does not match.', 'woocommerce' ), array( 'status' => 401 ) );
  355. }
  356. return true;
  357. }
  358. /**
  359. * Creates an array of urlencoded strings out of each array key/value pairs.
  360. *
  361. * @param array $params Array of parameters to convert.
  362. * @param array $query_params Array to extend.
  363. * @param string $key Optional Array key to append.
  364. * @return string Array of urlencoded strings.
  365. */
  366. private function join_with_equals_sign( $params, $query_params = array(), $key = '' ) {
  367. foreach ( $params as $param_key => $param_value ) {
  368. if ( $key ) {
  369. $param_key = $key . '%5B' . $param_key . '%5D'; // Handle multi-dimensional array.
  370. }
  371. if ( is_array( $param_value ) ) {
  372. $query_params = $this->join_with_equals_sign( $param_value, $query_params, $param_key );
  373. } else {
  374. $string = $param_key . '=' . $param_value; // Join with equals sign.
  375. $query_params[] = wc_rest_urlencode_rfc3986( $string );
  376. }
  377. }
  378. return $query_params;
  379. }
  380. /**
  381. * Normalize each parameter by assuming each parameter may have already been
  382. * encoded, so attempt to decode, and then re-encode according to RFC 3986.
  383. *
  384. * Note both the key and value is normalized so a filter param like:
  385. *
  386. * 'filter[period]' => 'week'
  387. *
  388. * is encoded to:
  389. *
  390. * 'filter%255Bperiod%255D' => 'week'
  391. *
  392. * This conforms to the OAuth 1.0a spec which indicates the entire query string
  393. * should be URL encoded.
  394. *
  395. * @see rawurlencode()
  396. * @param array $parameters Un-normalized parameters.
  397. * @return array Normalized parameters.
  398. */
  399. private function normalize_parameters( $parameters ) {
  400. $keys = wc_rest_urlencode_rfc3986( array_keys( $parameters ) );
  401. $values = wc_rest_urlencode_rfc3986( array_values( $parameters ) );
  402. $parameters = array_combine( $keys, $values );
  403. return $parameters;
  404. }
  405. /**
  406. * Verify that the timestamp and nonce provided with the request are valid. This prevents replay attacks where
  407. * an attacker could attempt to re-send an intercepted request at a later time.
  408. *
  409. * - A timestamp is valid if it is within 15 minutes of now.
  410. * - A nonce is valid if it has not been used within the last 15 minutes.
  411. *
  412. * @param stdClass $user User data.
  413. * @param int $timestamp The unix timestamp for when the request was made.
  414. * @param string $nonce A unique (for the given user) 32 alphanumeric string, consumer-generated.
  415. * @return bool|WP_Error
  416. */
  417. private function check_oauth_timestamp_and_nonce( $user, $timestamp, $nonce ) {
  418. global $wpdb;
  419. $valid_window = 15 * 60; // 15 minute window.
  420. if ( ( $timestamp < time() - $valid_window ) || ( $timestamp > time() + $valid_window ) ) {
  421. return new WP_Error( 'woocommerce_rest_authentication_error', __( 'Invalid timestamp.', 'woocommerce' ), array( 'status' => 401 ) );
  422. }
  423. $used_nonces = maybe_unserialize( $user->nonces );
  424. if ( empty( $used_nonces ) ) {
  425. $used_nonces = array();
  426. }
  427. if ( in_array( $nonce, $used_nonces, true ) ) {
  428. return new WP_Error( 'woocommerce_rest_authentication_error', __( 'Invalid nonce - nonce has already been used.', 'woocommerce' ), array( 'status' => 401 ) );
  429. }
  430. $used_nonces[ $timestamp ] = $nonce;
  431. // Remove expired nonces.
  432. foreach ( $used_nonces as $nonce_timestamp => $nonce ) {
  433. if ( $nonce_timestamp < ( time() - $valid_window ) ) {
  434. unset( $used_nonces[ $nonce_timestamp ] );
  435. }
  436. }
  437. $used_nonces = maybe_serialize( $used_nonces );
  438. $wpdb->update(
  439. $wpdb->prefix . 'woocommerce_api_keys',
  440. array( 'nonces' => $used_nonces ),
  441. array( 'key_id' => $user->key_id ),
  442. array( '%s' ),
  443. array( '%d' )
  444. );
  445. return true;
  446. }
  447. /**
  448. * Return the user data for the given consumer_key.
  449. *
  450. * @param string $consumer_key Consumer key.
  451. * @return array
  452. */
  453. private function get_user_data_by_consumer_key( $consumer_key ) {
  454. global $wpdb;
  455. $consumer_key = wc_api_hash( sanitize_text_field( $consumer_key ) );
  456. $user = $wpdb->get_row(
  457. $wpdb->prepare(
  458. "
  459. SELECT key_id, user_id, permissions, consumer_key, consumer_secret, nonces
  460. FROM {$wpdb->prefix}woocommerce_api_keys
  461. WHERE consumer_key = %s
  462. ",
  463. $consumer_key
  464. )
  465. );
  466. return $user;
  467. }
  468. /**
  469. * Check that the API keys provided have the proper key-specific permissions to either read or write API resources.
  470. *
  471. * @param string $method Request method.
  472. * @return bool|WP_Error
  473. */
  474. private function check_permissions( $method ) {
  475. $permissions = $this->user->permissions;
  476. switch ( $method ) {
  477. case 'HEAD':
  478. case 'GET':
  479. if ( 'read' !== $permissions && 'read_write' !== $permissions ) {
  480. return new WP_Error( 'woocommerce_rest_authentication_error', __( 'The API key provided does not have read permissions.', 'woocommerce' ), array( 'status' => 401 ) );
  481. }
  482. break;
  483. case 'POST':
  484. case 'PUT':
  485. case 'PATCH':
  486. case 'DELETE':
  487. if ( 'write' !== $permissions && 'read_write' !== $permissions ) {
  488. return new WP_Error( 'woocommerce_rest_authentication_error', __( 'The API key provided does not have write permissions.', 'woocommerce' ), array( 'status' => 401 ) );
  489. }
  490. break;
  491. case 'OPTIONS':
  492. return true;
  493. default:
  494. return new WP_Error( 'woocommerce_rest_authentication_error', __( 'Unknown request method.', 'woocommerce' ), array( 'status' => 401 ) );
  495. }
  496. return true;
  497. }
  498. /**
  499. * Updated API Key last access datetime.
  500. */
  501. private function update_last_access() {
  502. global $wpdb;
  503. $wpdb->update(
  504. $wpdb->prefix . 'woocommerce_api_keys',
  505. array( 'last_access' => current_time( 'mysql' ) ),
  506. array( 'key_id' => $this->user->key_id ),
  507. array( '%s' ),
  508. array( '%d' )
  509. );
  510. }
  511. /**
  512. * If the consumer_key and consumer_secret $_GET parameters are NOT provided
  513. * and the Basic auth headers are either not present or the consumer secret does not match the consumer
  514. * key provided, then return the correct Basic headers and an error message.
  515. *
  516. * @param WP_REST_Response $response Current response being served.
  517. * @return WP_REST_Response
  518. */
  519. public function send_unauthorized_headers( $response ) {
  520. if ( is_wp_error( $this->get_error() ) && 'basic_auth' === $this->auth_method ) {
  521. $auth_message = __( 'WooCommerce API. Use a consumer key in the username field and a consumer secret in the password field.', 'woocommerce' );
  522. $response->header( 'WWW-Authenticate', 'Basic realm="' . $auth_message . '"', true );
  523. }
  524. return $response;
  525. }
  526. /**
  527. * Check for user permissions and register last access.
  528. *
  529. * @param mixed $result Response to replace the requested version with.
  530. * @param WP_REST_Server $server Server instance.
  531. * @param WP_REST_Request $request Request used to generate the response.
  532. * @return mixed
  533. */
  534. public function check_user_permissions( $result, $server, $request ) {
  535. if ( $this->user ) {
  536. // Check API Key permissions.
  537. $allowed = $this->check_permissions( $request->get_method() );
  538. if ( is_wp_error( $allowed ) ) {
  539. return $allowed;
  540. }
  541. // Register last access.
  542. $this->update_last_access();
  543. }
  544. return $result;
  545. }
  546. }
  547. new WC_REST_Authentication();