From 0ff3fda3aca3ef21f6bccc05ee29fe69ce07c995 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Sun, 28 Jun 2020 00:37:55 +0300 Subject: [PATCH 1/2] Fix for Missing redirect error on redirect from OAuth when using the self-hosted instance success URL #454 --- app/controllers/api/account.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 3bce54eaf..8df3d3993 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -29,8 +29,8 @@ use DeviceDetector\DeviceDetector; use GeoIp2\Database\Reader; use Utopia\Validator\ArrayList; -$oauthDefaultSuccess = $request->getServer('_APP_HOME').'/auth/oauth2/success'; -$oauthDefaultFailure = $request->getServer('_APP_HOME').'/auth/oauth2/failure'; +$oauthDefaultSuccess = Config::getParam('protocol').'://'.Config::getParam('domain').'/auth/oauth2/success'; +$oauthDefaultFailure = Config::getParam('protocol').'://'.Config::getParam('domain').'/auth/oauth2/failure'; $oauth2Keys = []; @@ -509,7 +509,7 @@ $utopia->get('/v1/account/sessions/oauth2/:provider/redirect') ; } - if ($state['success'] === $oauthDefaultSuccess) { // Add keys for non-web platforms + if (substr($state['success'], 0, strlen($oauthDefaultSuccess) === $oauthDefaultSuccess)) { // Add keys for non-web platforms $state['success'] = URLParser::parse($state['success']); $query = URLParser::parseQuery($state['success']['query']); $query['project'] = $project->getId(); From 3a67ccb522a42a4f76ee9b90756da6491ba3cc7b Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Sun, 28 Jun 2020 10:59:52 +0300 Subject: [PATCH 2/2] Accept appwrite self hosted instances --- app/controllers/api/account.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 8df3d3993..516a2a258 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -29,8 +29,8 @@ use DeviceDetector\DeviceDetector; use GeoIp2\Database\Reader; use Utopia\Validator\ArrayList; -$oauthDefaultSuccess = Config::getParam('protocol').'://'.Config::getParam('domain').'/auth/oauth2/success'; -$oauthDefaultFailure = Config::getParam('protocol').'://'.Config::getParam('domain').'/auth/oauth2/failure'; +$oauthDefaultSuccess = '/auth/oauth2/success'; +$oauthDefaultFailure = '/auth/oauth2/failure'; $oauth2Keys = []; @@ -508,8 +508,9 @@ $utopia->get('/v1/account/sessions/oauth2/:provider/redirect') ->addHeader('X-Fallback-Cookies', \json_encode([Auth::$cookieName => Auth::encodeSession($user->getId(), $secret)])) ; } - - if (substr($state['success'], 0, strlen($oauthDefaultSuccess) === $oauthDefaultSuccess)) { // Add keys for non-web platforms + + // Add keys for non-web platforms - TODO - add verification phase to aviod session sniffing + if (parse_url($state['success'], PHP_URL_PATH) === $oauthDefaultSuccess) { $state['success'] = URLParser::parse($state['success']); $query = URLParser::parseQuery($state['success']['query']); $query['project'] = $project->getId();