From 50bda6ec6b925a2ac2d60a10e410edd8bba556b9 Mon Sep 17 00:00:00 2001 From: Sean Fahey Date: Wed, 30 Nov 2016 10:11:53 -0600 Subject: [PATCH] Add HTTP_X_FORWARDED_PROTO support to OAuth A tool provider behind a load balancer that passes requests internally over http will cause a "OAuth signature check failed" error. Check for a HTTP_X_FORWARDED_PROTO and HTTP_X_FORWARDED_PORT to build a correct request. Based off https://tracker.moodle.org/browse/MDL-49171 --- src/OAuth/OAuthRequest.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/OAuth/OAuthRequest.php b/src/OAuth/OAuthRequest.php index b7498f8..34983f2 100644 --- a/src/OAuth/OAuthRequest.php +++ b/src/OAuth/OAuthRequest.php @@ -38,10 +38,15 @@ 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']) && isset($_SERVER['HTTP_X_FORWARDED_PORT'])) { + $scheme = $_SERVER['HTTP_X_FORWARDED_PROTO']; + $port = $_SERVER['HTTP_X_FORWARDED_PORT']; + } $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'];