From 03c4f2af1316372b9a2f10cf494891b8d233bd42 Mon Sep 17 00:00:00 2001 From: lucs7 Date: Mon, 4 Aug 2025 17:07:06 +0200 Subject: [PATCH 1/2] fix: error in WebAuthenticationTest missing ILoginPage --- tests/Application/Authentication/WebAuthenticationTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Application/Authentication/WebAuthenticationTest.php b/tests/Application/Authentication/WebAuthenticationTest.php index 4fce6d2a5..e9a4f3a36 100644 --- a/tests/Application/Authentication/WebAuthenticationTest.php +++ b/tests/Application/Authentication/WebAuthenticationTest.php @@ -1,6 +1,7 @@ Date: Tue, 5 Aug 2025 11:20:29 -0700 Subject: [PATCH 2/2] fix: Facebook auth dependency failure Updates Facebook SDK package for compatibility and corrects exception handling for new SDK. Closes: #779 --- Presenters/LoginPresenter.php | 18 +++++++++++++++++- Web/facebook-auth.php | 22 ++++++++++++++++++++-- composer.json | 2 +- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/Presenters/LoginPresenter.php b/Presenters/LoginPresenter.php index 303750d3f..f29a17ba5 100644 --- a/Presenters/LoginPresenter.php +++ b/Presenters/LoginPresenter.php @@ -290,8 +290,24 @@ public function GetFacebookUrl() if (!session_id()) { session_start(); } + + // Build the full redirect URL + $redirectUri = Configuration::Instance()->GetSectionKey(ConfigSection::AUTHENTICATION, ConfigKeys::FACEBOOK_REDIRECT_URI); + $scriptUrl = Configuration::Instance()->GetScriptUrl(); + + $scriptUrl = rtrim($scriptUrl, '/'); + if (!str_starts_with($redirectUri, '/')) { + $redirectUri = '/' . $redirectUri; + } + + if (str_ends_with($scriptUrl, '/Web') && str_starts_with($redirectUri, '/Web/')) { + $redirectUri = substr($redirectUri, 4); // Remove the first "/Web" + } + + $fullRedirectUrl = $scriptUrl . $redirectUri; + $FacebookUrl = $helper->getLoginUrl( - Configuration::Instance()->GetSectionKey(ConfigSection::AUTHENTICATION, ConfigKeys::FACEBOOK_REDIRECT_URI), + $fullRedirectUrl, $permissions ); diff --git a/Web/facebook-auth.php b/Web/facebook-auth.php index d9a13b007..b7c104f21 100644 --- a/Web/facebook-auth.php +++ b/Web/facebook-auth.php @@ -15,13 +15,31 @@ ]); $helper = $facebook_Client->getRedirectLoginHelper(); - $accesstoken = $helper->getAccessToken(); + + // Build the full redirect URL to ensure consistency with login URL generation + $redirectUri = Configuration::Instance()->GetSectionKey(ConfigSection::AUTHENTICATION, ConfigKeys::FACEBOOK_REDIRECT_URI); + $scriptUrl = Configuration::Instance()->GetScriptUrl(); + + // Handle the case where script URL already ends with /Web and redirect URI starts with /Web + $scriptUrl = rtrim($scriptUrl, '/'); + if (!str_starts_with($redirectUri, '/')) { + $redirectUri = '/' . $redirectUri; + } + + // If script URL ends with /Web and redirect URI starts with /Web, remove the duplicate + if (str_ends_with($scriptUrl, '/Web') && str_starts_with($redirectUri, '/Web/')) { + $redirectUri = substr($redirectUri, 4); // Remove the first "/Web" + } + + $fullRedirectUrl = $scriptUrl . $redirectUri; + + $accesstoken = $helper->getAccessToken($fullRedirectUrl); $_SESSION['facebook_access_token'] = serialize($accesstoken); $code = filter_input(INPUT_GET,'code'); header("Location: ".ROOT_DIR."Web/external-auth.php?type=fb&code=".$code); exit; - } catch (\Facebook\Exceptions\FacebookResponseException | \Facebook\Exceptions\FacebookSDKException $e) { + } catch (\Facebook\Exception\ResponseException | \Facebook\Exception\SDKException $e) { Log::Debug("Exception during facebook login: %s", $e->getMessage()); $_SESSION['facebook_error'] = true; header("Location:".ROOT_DIR."Web"); diff --git a/composer.json b/composer.json index bd327a491..8acdea4f2 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "gregwar/captcha": "^1.3", "google/apiclient": "^2.0", "microsoft/microsoft-graph": "^2.0", - "nickdnk/graph-sdk": "^7.0", + "joelbutcher/facebook-graph-sdk": "^6.1", "mobiledetect/mobiledetectlib": "^4.8", "bacon/bacon-qr-code": "^3.0", "mibe/feedwriter": "^1.1",