Skip to content

Commit

Permalink
fix-external-url-handling
Browse files Browse the repository at this point in the history
  • Loading branch information
bumblecoder committed Sep 27, 2024
1 parent 0f8db87 commit 9cce4d1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/DependencyInjection/ProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
15 changes: 15 additions & 0 deletions tests/DependencyInjection/ProviderFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 9cce4d1

Please sign in to comment.