-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
284 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,47 +4,38 @@ | |
|
||
namespace League\Bundle\OAuth2ServerBundle\DependencyInjection\Security; | ||
|
||
use League\Bundle\OAuth2ServerBundle\Security\Authenticator\OAuth2Authenticator; | ||
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AuthenticatorFactoryInterface; | ||
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface; | ||
use Symfony\Component\Config\Definition\Builder\NodeDefinition; | ||
use Symfony\Component\DependencyInjection\ChildDefinition; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
/** | ||
* @author Mathias Arlaud <[email protected]> | ||
*/ | ||
final class OAuth2Factory implements SecurityFactoryInterface, AuthenticatorFactoryInterface | ||
{ | ||
public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint): array | ||
{ | ||
throw new \LogicException('OAuth2 is not supported when "security.enable_authenticator_manager" is not set to true.'); | ||
} | ||
|
||
public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId): string | ||
{ | ||
$authenticator = sprintf('security.authenticator.oauth2.%s', $firewallName); | ||
|
||
$definition = new ChildDefinition(OAuth2Authenticator::class); | ||
$definition->replaceArgument(2, new Reference($userProviderId)); | ||
|
||
$container->setDefinition($authenticator, $definition); | ||
|
||
return $authenticator; | ||
} | ||
|
||
public function getPosition(): string | ||
use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension; | ||
|
||
if (interface_exists(SecurityFactoryInterface::class) && !interface_exists(AuthenticatorFactoryInterface::class)) { | ||
/** | ||
* Wires the "oauth" authenticator from user configuration. | ||
* | ||
* @author Mathias Arlaud <[email protected]> | ||
*/ | ||
class OAuth2Factory implements SecurityFactoryInterface | ||
{ | ||
return 'pre_auth'; | ||
use OAuth2FactoryTrait; | ||
} | ||
|
||
public function getKey(): string | ||
} elseif (!method_exists(SecurityExtension::class, 'addAuthenticatorFactory')) { | ||
/** | ||
* Wires the "oauth" authenticator from user configuration. | ||
* | ||
* @author Mathias Arlaud <[email protected]> | ||
*/ | ||
class OAuth2Factory implements AuthenticatorFactoryInterface, SecurityFactoryInterface | ||
{ | ||
return 'oauth2'; | ||
use OAuth2FactoryTrait; | ||
} | ||
|
||
public function addConfiguration(NodeDefinition $builder): void | ||
} else { | ||
/** | ||
* Wires the "oauth" authenticator from user configuration. | ||
* | ||
* @author Mathias Arlaud <[email protected]> | ||
*/ | ||
class OAuth2Factory implements AuthenticatorFactoryInterface | ||
{ | ||
use OAuth2FactoryTrait; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace League\Bundle\OAuth2ServerBundle\DependencyInjection\Security; | ||
|
||
use League\Bundle\OAuth2ServerBundle\Security\Authenticator\OAuth2Authenticator; | ||
use Symfony\Component\Config\Definition\Builder\NodeDefinition; | ||
use Symfony\Component\DependencyInjection\ChildDefinition; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
/** | ||
* @author Mathias Arlaud <[email protected]> | ||
* @author Robin Chalas <[email protected]> | ||
*/ | ||
trait OAuth2FactoryTrait | ||
{ | ||
public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint): array | ||
{ | ||
throw new \LogicException('OAuth2 is not supported when "security.enable_authenticator_manager" is not set to true.'); | ||
} | ||
|
||
public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId): string | ||
{ | ||
$authenticator = sprintf('security.authenticator.oauth2.%s', $firewallName); | ||
|
||
$definition = new ChildDefinition(OAuth2Authenticator::class); | ||
$definition->replaceArgument(2, new Reference($userProviderId)); | ||
|
||
$container->setDefinition($authenticator, $definition); | ||
|
||
return $authenticator; | ||
} | ||
|
||
public function getPosition(): string | ||
{ | ||
return 'pre_auth'; | ||
} | ||
|
||
public function getPriority(): int | ||
{ | ||
return -10; | ||
} | ||
|
||
public function getKey(): string | ||
{ | ||
return 'oauth2'; | ||
} | ||
|
||
public function addConfiguration(NodeDefinition $builder): void | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/Security/Authenticator/ForwardCompatAuthenticatorTrait.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace League\Bundle\OAuth2ServerBundle\Security\Authenticator; | ||
|
||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface; | ||
use Symfony\Component\Security\Http\Authenticator\Passport\Passport; | ||
use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface; | ||
|
||
/** @var \ReflectionNamedType|null $r */ | ||
$r = (new \ReflectionMethod(AuthenticatorInterface::class, 'authenticate'))->getReturnType(); | ||
|
||
if ($r && Passport::class === $r->getName()) { | ||
/** | ||
* @internal | ||
* | ||
* @psalm-suppress UnrecognizedStatement | ||
*/ | ||
trait ForwardCompatAuthenticatorTrait | ||
{ | ||
public function authenticate(Request $request): Passport | ||
{ | ||
return $this->doAuthenticate($request); | ||
} | ||
} | ||
} else { | ||
/** | ||
* @internal | ||
* | ||
* @psalm-suppress UnrecognizedStatement | ||
*/ | ||
trait ForwardCompatAuthenticatorTrait | ||
{ | ||
public function authenticate(Request $request): PassportInterface | ||
{ | ||
return $this->doAuthenticate($request); | ||
} | ||
} | ||
} |
Oops, something went wrong.