Skip to content

Commit

Permalink
Merge pull request #990 from bdovaz/fix-redirect-url
Browse files Browse the repository at this point in the history
Use absolute paths instead of relative paths
  • Loading branch information
julien-nc authored Dec 4, 2024
2 parents 0c2f96a + bbf13e6 commit 10dec7f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ private function checkLoginToken(TokenService $tokenService): void {
private function registerRedirect(IRequest $request, IURLGenerator $urlGenerator, SettingsService $settings, ProviderMapper $providerMapper): void {
$providers = $this->getCachedProviders($providerMapper);
$redirectUrl = $request->getParam('redirect_url');
$absoluteRedirectUrl = !empty($redirectUrl) ? $urlGenerator->getAbsoluteURL($redirectUrl) : $redirectUrl;

// Handle immediate redirect to the oidc provider if just one is configured and no other backends are allowed
$isDefaultLogin = false;
Expand All @@ -92,7 +93,7 @@ private function registerRedirect(IRequest $request, IURLGenerator $urlGenerator
if ($isDefaultLogin && !$settings->getAllowMultipleUserBackEnds() && count($providers) === 1) {
$targetUrl = $urlGenerator->linkToRoute(self::APP_ID . '.login.login', [
'providerId' => $providers[0]->getId(),
'redirectUrl' => $redirectUrl
'redirectUrl' => $absoluteRedirectUrl
]);
header('Location: ' . $targetUrl);
exit();
Expand All @@ -101,12 +102,13 @@ private function registerRedirect(IRequest $request, IURLGenerator $urlGenerator

private function registerLogin(IRequest $request, IL10N $l10n, IURLGenerator $urlGenerator, ProviderMapper $providerMapper): void {
$redirectUrl = $request->getParam('redirect_url');
$absoluteRedirectUrl = !empty($redirectUrl) ? $urlGenerator->getAbsoluteURL($redirectUrl) : $redirectUrl;
$providers = $this->getCachedProviders($providerMapper);
foreach ($providers as $provider) {
// FIXME: Move to IAlternativeLogin but requires boot due to db connection
OC_App::registerLogIn([
'name' => $l10n->t('Login with %1s', [$provider->getIdentifier()]),
'href' => $urlGenerator->linkToRoute(self::APP_ID . '.login.login', ['providerId' => $provider->getId(), 'redirectUrl' => $redirectUrl]),
'href' => $urlGenerator->linkToRoute(self::APP_ID . '.login.login', ['providerId' => $provider->getId(), 'redirectUrl' => $absoluteRedirectUrl]),
]);
}

Expand Down

0 comments on commit 10dec7f

Please sign in to comment.