3namespace ceLTIc\LTI\OAuth;
87 if ((isset($_SERVER[
'HTTP_X_FORWARDED_PROTO']) && ($_SERVER[
'HTTP_X_FORWARDED_PROTO'] ===
'https')) ||
88 (isset($_SERVER[
'HTTP_X_FORWARDED_SSL']) && ($_SERVER[
'HTTP_X_FORWARDED_SSL'] ===
'on')) ||
89 (isset($_SERVER[
'HTTP_X_URL_SCHEME']) && ($_SERVER[
'HTTP_X_URL_SCHEME'] ===
'https'))) {
90 $_SERVER[
'HTTPS'] =
'on';
91 $_SERVER[
'SERVER_PORT'] = 443;
92 } elseif (isset($_SERVER[
'HTTP_X_FORWARDED_PROTO'])) {
93 $_SERVER[
'HTTPS'] =
'off';
94 $_SERVER[
'SERVER_PORT'] = 80;
95 } elseif (!isset($_SERVER[
'HTTPS'])) {
96 $_SERVER[
'HTTPS'] =
'off';
98 if (!empty($_SERVER[
'HTTP_X_FORWARDED_HOST'])) {
99 $forwardedHosts = str_replace(
' ',
',', trim($_SERVER[
'HTTP_X_FORWARDED_HOST']));
100 $hosts = explode(
',', $forwardedHosts);
101 if (!empty($hosts[0])) {
102 $host = explode(
':', $hosts[0], 2);
103 $_SERVER[
'SERVER_NAME'] = $host[0];
104 if (count($host) > 1) {
105 $_SERVER[
'SERVER_PORT'] = $host[1];
106 } elseif ($_SERVER[
'HTTPS'] ===
'on') {
107 $_SERVER[
'SERVER_PORT'] = 443;
109 $_SERVER[
'SERVER_PORT'] = 80;
112 } elseif (!empty($_SERVER[
'HTTP_X_ORIGINAL_HOST'])) {
113 $_SERVER[
'SERVER_NAME'] = $_SERVER[
'HTTP_X_ORIGINAL_HOST'];
115 $scheme = ($_SERVER[
'HTTPS'] ===
'on') ?
'https' :
'http';
116 $http_url =
"{$scheme}://{$_SERVER['SERVER_NAME']}:{$_SERVER['SERVER_PORT']}{$_SERVER['REQUEST_URI']}";
129 if (isset($_SERVER[
'QUERY_STRING'])) {
135 if ((
$http_method ===
'POST' && isset($request_headers[
'Content-Type']) && stristr($request_headers[
'Content-Type'],
136 'application/x-www-form-urlencoded')) || !empty($_POST)) {
145 if (isset($request_headers[
'Authorization']) && substr($request_headers[
'Authorization'], 0, 6) ==
'OAuth ') {
169 'oauth_nonce' => OAuthRequest::generate_nonce(),
170 'oauth_timestamp' => OAuthRequest::generate_timestamp(),
171 'oauth_consumer_key' => $consumer->key);
173 $defaults[
'oauth_token'] = $token->key;
189 if ($allow_duplicates && isset($this->parameters[$name])) {
191 if (is_scalar($this->parameters[$name])) {
194 $this->parameters[$name] = array($this->parameters[$name]);
197 $this->parameters[$name][] = $value;
199 $this->parameters[$name] = $value;
212 return isset($this->parameters[$name]) ? $this->parameters[$name] :
null;
232 unset($this->parameters[$name]);
247 if (isset($params[
'oauth_signature'])) {
248 unset($params[
'oauth_signature']);
273 return implode(
'&', $parts);
283 return strtoupper($this->http_method);
293 $parts = parse_url($this->http_url);
295 $scheme = (isset($parts[
'scheme'])) ? $parts[
'scheme'] :
'http';
296 $port = (isset($parts[
'port'])) ? $parts[
'port'] : (($scheme ==
'https') ?
'443' :
'80');
297 $host = (isset($parts[
'host'])) ? strtolower($parts[
'host']) :
'';
298 $path = (isset($parts[
'path'])) ? $parts[
'path'] :
'';
300 if (($scheme ==
'https' && $port !=
'443') || ($scheme ==
'http' && $port !=
'80')) {
301 $host =
"$host:$port";
304 return "$scheme://$host$path";
317 $out .=
'?' . $post_data;
348 $out =
'Authorization: OAuth';
351 foreach ($this->parameters as $k => $v) {
352 if (substr($k, 0, 5) !=
"oauth")
357 $out .= ($first) ?
' ' :
',';
388 "oauth_signature_method", $signature_method->get_name(),
false
390 $signature = $this->
build_signature($signature_method, $consumer, $token);
405 $signature = $signature_method->build_signature($this, $consumer, $token);
414 private static function generate_timestamp()
424 private static function generate_nonce()
429 return md5($mt . $rand);
Class to represent an OAuth Exception.
Class to represent an OAuth request.
build_signature($signature_method, $consumer, $token)
Build the signature.
unset_parameter($name)
Delete a parameter.
__construct($http_method, $http_url, $parameters=null)
Class constructor.
get_signature_base_string()
Returns the base string of this request.
to_url()
Builds a url usable for a GET request.
get_signable_parameters()
The request parameters, sorted and concatenated into a normalized string.
get_normalized_http_method()
Just uppercases the http method.
to_postdata()
Builds the data one would send in a POST request.
static from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters=null)
Pretty much a helper function to set up the request.
$parameters
Request parameters.
__toString()
Convert object to a string.
get_parameters()
Get request parameters.
static from_request($http_method=null, $http_url=null, $parameters=null)
Attempt to build up a request from what was passed to the server.
sign_request($signature_method, $consumer, $token)
Sign the request.
get_normalized_http_url()
Parses the url and rebuilds it to be scheme://host/path.
to_header($realm=null)
Builds the Authorization: header.
set_parameter($name, $value, $allow_duplicates=true)
Set a parameter.
get_parameter($name)
Get a parameter.
static $POST_INPUT
Access to POST data.
static build_http_query($params)
Build HTTP query string.
static split_header($header, $only_allow_oauth_parameters=true)
Utility function for turning the Authorization: header into parameters, has to do some unescaping.
static urlencode_rfc3986($input)
URL encode.
static parse_parameters($input)
Parse parameters.
static get_headers()
Helper to try to sort out headers for people who aren't running apache.