From 9cce4d1ce6aa8d9ac2c2334ae93c4e9c46c72956 Mon Sep 17 00:00:00 2001 From: Anton Bielykh Date: Thu, 26 Sep 2024 18:18:50 -0600 Subject: [PATCH] fix-external-url-handling --- src/DependencyInjection/ProviderFactory.php | 6 ++++-- tests/DependencyInjection/ProviderFactoryTest.php | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/DependencyInjection/ProviderFactory.php b/src/DependencyInjection/ProviderFactory.php index 87dddb93..0c80cf59 100644 --- a/src/DependencyInjection/ProviderFactory.php +++ b/src/DependencyInjection/ProviderFactory.php @@ -37,8 +37,10 @@ public function __construct(UrlGeneratorInterface $generator) public function createProvider($class, array $options, ?string $redirectUri = null, array $redirectParams = [], array $collaborators = []) { if (null !== $redirectUri) { - $redirectUri = $this->generator - ->generate($redirectUri, $redirectParams, UrlGeneratorInterface::ABSOLUTE_URL); + if (!filter_var($redirectUri, FILTER_VALIDATE_URL)) { + $redirectUri = $this->generator + ->generate($redirectUri, $redirectParams, UrlGeneratorInterface::ABSOLUTE_URL); + } $options['redirectUri'] = $redirectUri; } diff --git a/tests/DependencyInjection/ProviderFactoryTest.php b/tests/DependencyInjection/ProviderFactoryTest.php index 36921b00..1b69c13b 100644 --- a/tests/DependencyInjection/ProviderFactoryTest.php +++ b/tests/DependencyInjection/ProviderFactoryTest.php @@ -45,6 +45,21 @@ public function testShouldCreateProviderWithNullRedirectUrl() $this->assertEquals([], $result->getCollaborators()); } + public function testShouldCreateProviderWithExternalRedirectUrl() + { + $mockGenerator = $this->getMockBuilder(UrlGeneratorInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $mockGenerator->expects($this->never())->method('generate'); + + $testProviderFactory = new ProviderFactory($mockGenerator); + $externalRedirectUri = 'https://external-site.com/callback'; + $result = $testProviderFactory->createProvider(MockProvider::class, [], $externalRedirectUri); + + $this->assertInstanceOf(MockProvider::class, $result); + $this->assertEquals(['redirectUri' => $externalRedirectUri], $result->getOptions()); + } + private function getMockGenerator($generateReturn) { $mockGenerator = $this->getMockBuilder(UrlGeneratorInterface::class)->disableOriginalConstructor()->getMock();