private function init_request() { $this->request = OAuthRequest::from_request(); /* Verify if the request was issued with proper HTTP method. */ if (!in_array($this->request->get_normalized_http_method(), array('GET', 'POST'))) { throw new BadRequest("Use GET and POST methods only."); } /* Verify if the request was issued with proper okapi_base_url. */ $url = $this->request->get_normalized_http_url(); $allowed = false; foreach (Okapi::get_allowed_base_urls() as $allowed_prefix) { if (strpos($url, $allowed_prefix) === 0) { $allowed = true; break; } } if (!$allowed) { throw new BadRequest("Unrecognized base URL prefix! See `okapi_base_urls` field " . "in the `services/apisrv/installation` method. (Recommended " . "base URL to use is '" . Okapi::get_recommended_base_url() . "'.)"); } }
/** * pretty much a helper function to set up the request */ public static function from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters = NULL) { $parameters = $parameters ? $parameters : array(); $defaults = array("oauth_version" => OAuthRequest::$version, "oauth_nonce" => OAuthRequest::generate_nonce(), "oauth_timestamp" => OAuthRequest::generate_timestamp(), "oauth_consumer_key" => $consumer->key); if ($token) { $defaults['oauth_token'] = $token->key; } $parameters = array_merge($defaults, $parameters); return new OAuthRequest($http_method, $http_url, $parameters); }