Skip to content

Commit

Permalink
feature #381 Allow null as redirect_route (toooni)
Browse files Browse the repository at this point in the history
This PR was merged into the master branch.

Discussion
----------

Allow null as redirect_route

The functionality “Fetching access keys via OAuth2 to be used with an API” mentioned in the README does not necessarily need a `redirect_url`, thus providing it should not be mandatory. We have an Endpoint (pingen.com) which does not allow `redirect_url` to be sent in these cases. Also, it wouldn't make much sense if it did because the route must be a valid symfony route, which in some cases must be created without a use.
I also think it makes sense to allow `null` here because this parameter isn't mandatory in the `League\OAuth2\Client\ProviderAbstractProvider` (https://github.com/thephpleague/oauth2-client/blob/master/src/Provider/AbstractProvider.php#L454).

Commits
-------

cb50093 Allow null as redirect_route
  • Loading branch information
weaverryan committed Oct 31, 2022
2 parents 31b3b30 + cb50093 commit 355fb37
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/DependencyInjection/ProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ public function __construct(UrlGeneratorInterface $generator)
*
* @return mixed
*/
public function createProvider($class, array $options, $redirectUri, array $redirectParams = [], array $collaborators = [])
public function createProvider($class, array $options, string $redirectUri = null, array $redirectParams = [], array $collaborators = [])
{
$redirectUri = $this->generator
->generate($redirectUri, $redirectParams, UrlGeneratorInterface::ABSOLUTE_URL);
if ($redirectUri !== null) {
$redirectUri = $this->generator
->generate($redirectUri, $redirectParams, UrlGeneratorInterface::ABSOLUTE_URL);

$options['redirectUri'] = $redirectUri;
$options['redirectUri'] = $redirectUri;
}

return new $class($options, $collaborators);
}
Expand Down
13 changes: 13 additions & 0 deletions tests/DependencyInjection/ProviderFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ public function testShouldCreateProvider()
$this->assertEquals([], $result->getCollaborators());
}

public function testShouldCreateProviderWithNullRedirectUrl()
{
$mockGenerator = $this->getMockBuilder(UrlGeneratorInterface::class)->disableOriginalConstructor()->getMock();
$mockGenerator->expects($this->never())->method("generate");

$testProviderFactory = new ProviderFactory($mockGenerator);
$result = $testProviderFactory->createProvider(MockProvider::class, [], null);

$this->assertInstanceOf(MockProvider::class, $result);
$this->assertEquals([], $result->getOptions());
$this->assertEquals([], $result->getCollaborators());
}

private function getMockGenerator($generateReturn)
{
$mockGenerator = $this->getMockBuilder(UrlGeneratorInterface::class)->disableOriginalConstructor()->getMock();
Expand Down

0 comments on commit 355fb37

Please sign in to comment.