diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 0ae4e19f43..f18cb27834 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -1953,7 +1953,16 @@ App::get('/v1/account/tokens/oauth2/:provider') ->inject('project') ->inject('platform') ->action(function (string $provider, string $success, string $failure, array $scopes, Request $request, Response $response, Document $project, array $platform) use ($oauthDefaultSuccess, $oauthDefaultFailure) { - $callback = $platform['endpoint'] . '/account/sessions/oauth2/callback/' . $provider . '/' . $project->getId(); + $protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') === 'disabled' ? 'http' : 'https'; + $port = $request->getPort(); + $callbackBase = $protocol . '://' . $request->getHostname(); + if ($protocol === 'https' && $port !== '443') { + $callbackBase .= ':' . $port; + } elseif ($protocol === 'http' && $port !== '80') { + $callbackBase .= ':' . $port; + } + + $callback = $callbackBase . '/v1/account/sessions/oauth2/callback/' . $provider . '/' . $project->getId(); $providerEnabled = $project->getAttribute('oAuthProviders', [])[$provider . 'Enabled'] ?? false; if (!$providerEnabled) {