From 2548a592f1bf7ee342d87bbc6473acd48f2e3aa1 Mon Sep 17 00:00:00 2001 From: Alejandro Liu Date: Mon, 27 May 2019 21:40:40 +0200 Subject: [PATCH 1/3] Address issue #58 Signed-off-by: Alejandro Liu --- lib/basicauth.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lib/basicauth.php b/lib/basicauth.php index bdb89ef..a4a1a0f 100644 --- a/lib/basicauth.php +++ b/lib/basicauth.php @@ -24,6 +24,31 @@ class OC_User_BasicAuth extends \OCA\user_external\Base { * @return true/false */ public function checkPassword($uid, $password) { + /* + * Connect without user/name password to make sure + * URL is indeed authenticating or not... + */ + stream_context_set_default(array( + 'http'=>array( + 'method'=>"GET", + )) + ); + $headers = get_headers($this->authUrl, 1); + if(!$headers) { + OC::$server->getLogger()->error( + 'ERROR: Not possible to connect to BasicAuth Url: '.$this->authUrl, + ['app' => 'user_external'] + ); + return false; + } + if (!isset($headers['WWW-Authenticate'])) { + OC::$server->getLogger()->error( + 'ERROR: Mis-configured BasicAuth Url: '.$this->authUrl, + ['app' => 'user_external'] + ); + return false; + } + stream_context_set_default(array( 'http'=>array( 'method'=>"GET", From f03cd092fe80eb08fae7ad77e0e3e42175d2c369 Mon Sep 17 00:00:00 2001 From: Alejandro Liu Date: Sat, 1 Jun 2019 19:18:53 +0200 Subject: [PATCH 2/3] Renaming the variable used for checs, adding more explanatory text Signed-off-by: Alejandro Liu --- lib/basicauth.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/basicauth.php b/lib/basicauth.php index a4a1a0f..7bf608a 100644 --- a/lib/basicauth.php +++ b/lib/basicauth.php @@ -33,17 +33,17 @@ class OC_User_BasicAuth extends \OCA\user_external\Base { 'method'=>"GET", )) ); - $headers = get_headers($this->authUrl, 1); - if(!$headers) { + $canary = get_headers($this->authUrl, 1); + if(!$canary) { OC::$server->getLogger()->error( 'ERROR: Not possible to connect to BasicAuth Url: '.$this->authUrl, ['app' => 'user_external'] ); return false; } - if (!isset($headers['WWW-Authenticate'])) { + if (!isset($canary['WWW-Authenticate'])) { OC::$server->getLogger()->error( - 'ERROR: Mis-configured BasicAuth Url: '.$this->authUrl, + 'ERROR: Mis-configured BasicAuth Url: '.$this->authUrl.', provided URL does not do authentication!', ['app' => 'user_external'] ); return false; From f3302a352c28c335f8b43e79daf5fa78f498af09 Mon Sep 17 00:00:00 2001 From: Alejandro Liu Date: Mon, 3 Jun 2019 08:54:57 +0200 Subject: [PATCH 3/3] Make sure check of headers is case insensitive. Signed-off-by: Alejandro Liu --- lib/basicauth.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/basicauth.php b/lib/basicauth.php index 7bf608a..c6e55f1 100644 --- a/lib/basicauth.php +++ b/lib/basicauth.php @@ -41,7 +41,7 @@ class OC_User_BasicAuth extends \OCA\user_external\Base { ); return false; } - if (!isset($canary['WWW-Authenticate'])) { + if (!isset(array_change_key_case($canary, CASE_LOWER)['www-authenticate'])) { OC::$server->getLogger()->error( 'ERROR: Mis-configured BasicAuth Url: '.$this->authUrl.', provided URL does not do authentication!', ['app' => 'user_external']