38 $scheme = (!isset($_SERVER[
'HTTPS']) || $_SERVER[
'HTTPS'] !=
"on")
42 '://' . $_SERVER[
'SERVER_NAME'] .
44 $_SERVER[
'SERVER_PORT'] .
45 $_SERVER[
'REQUEST_URI'];
57 if (isset($_SERVER[
'QUERY_STRING'])) {
66 && isset($request_headers[
'Content-Type'])
67 && strstr($request_headers[
'Content-Type'],
'application/x-www-form-urlencoded')) {
74 if (isset($request_headers[
'Authorization']) && substr($request_headers[
'Authorization'], 0, 6) ==
'OAuth ') {
91 'oauth_nonce' => OAuthRequest::generate_nonce(),
92 'oauth_timestamp' => OAuthRequest::generate_timestamp(),
93 'oauth_consumer_key' => $consumer->key);
95 $defaults[
'oauth_token'] = $token->key;
105 if ($allow_duplicates && isset($this->parameters[$name])) {
107 if (is_scalar($this->parameters[$name])) {
110 $this->parameters[$name] = array($this->parameters[$name]);
113 $this->parameters[$name][] = $value;
115 $this->parameters[$name] = $value;
120 return isset($this->parameters[$name]) ? $this->parameters[$name] : null;
128 unset($this->parameters[$name]);
142 if (isset($params[
'oauth_signature'])) {
143 unset($params[
'oauth_signature']);
166 return implode(
'&', $parts);
174 return strtoupper($this->http_method);
183 $parts = parse_url($this->http_url);
185 $scheme = (isset($parts[
'scheme'])) ? $parts[
'scheme'] :
'http';
186 $port = (isset($parts[
'port'])) ? $parts[
'port'] : (($scheme ==
'https') ?
'443' :
'80');
187 $host = (isset($parts[
'host'])) ? strtolower($parts[
'host']) :
'';
188 $path = (isset($parts[
'path'])) ? $parts[
'path'] :
'';
190 if (($scheme ==
'https' && $port !=
'443')
191 || ($scheme ==
'http' && $port !=
'80')) {
192 $host =
"$host:$port";
195 return "$scheme://$host$path";
207 $out .=
'?'.$post_data;
231 $out =
'Authorization: OAuth';
234 foreach ($this->parameters as $k => $v) {
235 if (substr($k, 0, 5) !=
"oauth")
continue;
239 $out .= ($first) ?
' ' :
',';
259 "oauth_signature_method",
260 $signature_method->get_name(),
263 $signature = $this->
build_signature($signature_method, $consumer, $token);
269 $signature = $signature_method->build_signature($this, $consumer, $token);
276 private static function generate_timestamp() {
283 private static function generate_nonce() {
287 return md5($mt . $rand);
to_url()
builds a url usable for a GET request
get_normalized_http_url()
parses the url and rebuilds it to be scheme://host/path
build_signature($signature_method, $consumer, $token)
sign_request($signature_method, $consumer, $token)
to_postdata()
builds the data one would send in a POST request
Class to represent an OAuth Exception.
static from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters=null)
pretty much a helper function to set up the request
get_normalized_http_method()
just uppercases the http method
set_parameter($name, $value, $allow_duplicates=true)
to_header($realm=null)
builds the Authorization: header
static urlencode_rfc3986($input)
get_signature_base_string()
Returns the base string of this request.
static from_request($http_method=null, $http_url=null, $parameters=null)
attempt to build up a request from what was passed to the server
get_signable_parameters()
The request parameters, sorted and concatenated into a normalized string.
static split_header($header, $only_allow_oauth_parameters=true)
static build_http_query($params)
Class to represent an OAuth Request.
__construct($http_method, $http_url, $parameters=null)
static parse_parameters($input)