/**
  * Generate a new access token
  *
  * @param string $oauth_consumer_key Consumer key
  * @param string $oauth_token Request token key
  * @return WP_Error|array OAuth token data on success, error otherwise
  */
 public function generate_access_token($oauth_consumer_key, $oauth_token, $oauth_verifier)
 {
     $token = $this->get_request_token($oauth_token);
     if (is_wp_error($token)) {
         return $token;
     }
     // Check verification
     if ($token['authorized'] !== true) {
         return new WP_Error('json_oauth1_unauthorized_token', __('OAuth token has not been authorized'), array('status' => 401));
     }
     if ($oauth_verifier !== $token['verifier']) {
         return new WP_Error('json_oauth1_invalid_verifier', __('OAuth verifier does not match'), array('status' => 400));
     }
     $this->should_attempt = false;
     $consumer = WP_REST_OAuth1_Client::get_by_key($oauth_consumer_key);
     $this->should_attempt = true;
     if (is_wp_error($consumer)) {
         return $consumer;
     }
     // Issue access token
     $key = apply_filters('json_oauth1_access_token_key', wp_generate_password(self::TOKEN_KEY_LENGTH, false));
     $data = array('key' => $key, 'secret' => wp_generate_password(self::TOKEN_SECRET_LENGTH, false), 'consumer' => $consumer->ID, 'user' => $token['user']);
     $data = apply_filters('json_oauth1_access_token_data', $data);
     add_option('oauth1_access_' . $key, $data, null, 'no');
     // Delete the request token
     $this->remove_request_token($oauth_token);
     // Return the new token's data
     $data = array('oauth_token' => self::urlencode_rfc3986($key), 'oauth_token_secret' => self::urlencode_rfc3986($data['secret']));
     return $data;
 }
 /**
  * Generate a new access token
  *
  * @param string $oauth_consumer_key Consumer key
  * @param string $oauth_token Request token key
  * @return WP_Error|array OAuth token data on success, error otherwise
  */
 public function generate_access_token($params)
 {
     $consumer = WP_REST_OAuth1_Client::get_by_key($params['oauth_consumer_key']);
     if (is_wp_error($consumer)) {
         return $consumer;
     }
     $token = $this->get_request_token($params['oauth_token']);
     if (is_wp_error($token)) {
         return $token;
     }
     // Check the OAuth request signature against the current request
     $result = $this->check_oauth_signature($consumer, $params, $token);
     if (is_wp_error($result)) {
         return $result;
     }
     $error = $this->check_oauth_timestamp_and_nonce($consumer, $params['oauth_timestamp'], $params['oauth_nonce']);
     if (is_wp_error($error)) {
         return $error;
     }
     // Check verification
     if ($token['authorized'] !== true) {
         return new WP_Error('json_oauth1_unauthorized_token', __('OAuth token has not been authorized', 'rest_oauth1'), array('status' => 401));
     }
     if (!hash_equals((string) $params['oauth_verifier'], (string) $token['verifier'])) {
         return new WP_Error('json_oauth1_invalid_verifier', __('OAuth verifier does not match', 'rest_oauth1'), array('status' => 400));
     }
     $this->should_attempt = false;
     $consumer = WP_REST_OAuth1_Client::get_by_key($params['oauth_consumer_key']);
     $this->should_attempt = true;
     if (is_wp_error($consumer)) {
         return $consumer;
     }
     // Issue access token
     $key = apply_filters('json_oauth1_access_token_key', wp_generate_password(self::TOKEN_KEY_LENGTH, false));
     $data = array('key' => $key, 'secret' => wp_generate_password(self::TOKEN_SECRET_LENGTH, false), 'consumer' => $consumer->ID, 'user' => $token['user']);
     $data = apply_filters('json_oauth1_access_token_data', $data);
     add_option('oauth1_access_' . $key, $data, null, 'no');
     // Delete the request token
     $this->remove_request_token($params['oauth_token']);
     // Return the new token's data
     $data = array('oauth_token' => self::urlencode_rfc3986($key), 'oauth_token_secret' => self::urlencode_rfc3986($data['secret']));
     return $data;
 }