From 708c3234f8aa91b213622e7e8cd849e43280d402 Mon Sep 17 00:00:00 2001 From: Renaat De Muynck Date: Tue, 30 Jan 2018 14:46:02 +0100 Subject: [PATCH] Add HTTP_X_FORWARDED support to OAuth --- src/OAuth/OAuthRequest.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/OAuth/OAuthRequest.php b/src/OAuth/OAuthRequest.php index b7498f8..aca2d0c 100644 --- a/src/OAuth/OAuthRequest.php +++ b/src/OAuth/OAuthRequest.php @@ -38,10 +38,20 @@ public static function from_request($http_method = null, $http_url = null, $para $scheme = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != "on") ? 'http' : 'https'; + $port = $_SERVER['SERVER_PORT']; + if ( isset($_SERVER['HTTP_X_FORWARDED_PROTO']) ) { + $scheme = $_SERVER['HTTP_X_FORWARDED_PROTO']; + + if ( isset( $_SERVER['HTTP_X_FORWARDED_PORT'] ) ) { + $port = $_SERVER['HTTP_X_FORWARDED_PORT']; + } else if ( 'https' == $_SERVER['HTTP_X_FORWARDED_PROTO'] ) { + $port = 443; + } + } $http_url = ($http_url) ? $http_url : $scheme . '://' . $_SERVER['SERVER_NAME'] . ':' . - $_SERVER['SERVER_PORT'] . + $port . $_SERVER['REQUEST_URI']; $http_method = ($http_method) ? $http_method : $_SERVER['REQUEST_METHOD'];