Skip to content

Commit 65e711e

Browse files
committed
Added support for XFP and XFH headers to OAuth (1EdTech#41).
Fixed $http_url to respect Host header instead SERVER_NAME (1EdTech#46).
1 parent 4a75343 commit 65e711e

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/OAuth/OAuthRequest.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@ function __construct($http_method, $http_url, $parameters = null) {
3535
*/
3636
public static function from_request($http_method = null, $http_url = null, $parameters = null) {
3737

38-
$scheme = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != "on")
39-
? 'http'
40-
: 'https';
41-
$http_url = ($http_url) ? $http_url : $scheme .
42-
'://' . $_SERVER['SERVER_NAME'] .
43-
':' .
44-
$_SERVER['SERVER_PORT'] .
45-
$_SERVER['REQUEST_URI'];
38+
if (!$http_url) {
39+
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
40+
$scheme = ($_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') ? 'https' : 'http';
41+
} else {
42+
$scheme = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != "on") ? 'http' : 'https';
43+
}
44+
$host = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST'];
45+
$http_url = $scheme . '://' . $host . $_SERVER['REQUEST_URI'];
46+
}
4647
$http_method = ($http_method) ? $http_method : $_SERVER['REQUEST_METHOD'];
4748

4849
// We weren't handed any parameters, so let's find the ones relevant to

0 commit comments

Comments
 (0)