-
-
Notifications
You must be signed in to change notification settings - Fork 614
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
7 changed files
with
199 additions
and
86 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
83 changes: 83 additions & 0 deletions
83
DependencyInjection/Security/Factory/JWTAuthenticatorFactoryTrait.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,83 @@ | ||
<?php | ||
|
||
namespace Lexik\Bundle\JWTAuthenticationBundle\DependencyInjection\Security\Factory; | ||
|
||
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AuthenticatorFactoryInterface; | ||
use Symfony\Component\Config\Definition\Builder\NodeDefinition; | ||
use Symfony\Component\DependencyInjection\ChildDefinition; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
/** | ||
* Wires the "jwt" authenticator from user configuration. | ||
* | ||
* @author Robin Chalas <robin.chalas@gmail.com> | ||
*/ | ||
trait JWTAuthenticatorFactoryTrait | ||
{ | ||
/** | ||
* @throws \LogicException | ||
* | ||
* @return array | ||
*/ | ||
public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint) | ||
{ | ||
throw new \LogicException('This method is implemented for BC purpose and should never be called.'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getPriority(): int | ||
{ | ||
return -10; | ||
} | ||
|
||
public function getPosition(): string | ||
{ | ||
return 'pre_auth'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getKey(): string | ||
{ | ||
return 'jwt'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function addConfiguration(NodeDefinition $node) | ||
{ | ||
$node | ||
->children() | ||
->scalarNode('provider') | ||
->defaultNull() | ||
->end() | ||
->scalarNode('authenticator') | ||
->defaultValue('lexik_jwt_authentication.security.jwt_authenticator') | ||
->end() | ||
->end() | ||
; | ||
} | ||
|
||
public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId): string | ||
{ | ||
$authenticatorId = 'security.authenticator.jwt.'.$firewallName; | ||
|
||
$userProviderId = empty($config['provider']) ? $userProviderId : 'security.user.provider.concrete.' . $config['provider']; | ||
|
||
$container | ||
->setDefinition($authenticatorId, new ChildDefinition($config['authenticator'])) | ||
->replaceArgument(3, new Reference($userProviderId)) | ||
; | ||
|
||
// Compile-time parameter removed by RemoveLegacyAuthenticatorPass | ||
// Stop setting it when guard support gets removed (aka when removing Symfony<5.3 support) | ||
$container->setParameter('lexik_jwt_authentication.authenticator_manager_enabled', true); | ||
|
||
return $authenticatorId; | ||
} | ||
} |
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
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 | ||
|
||
namespace Lexik\Bundle\JWTAuthenticationBundle\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; | ||
|
||
$r = new \ReflectionMethod(AuthenticatorInterface::class, 'authenticate'); | ||
|
||
if ($r->hasReturnType() && Passport::class === $r->getReturnType()->getName()) { | ||
eval(' | ||
namespace Lexik\Bundle\JWTAuthenticationBundle\Security\Authenticator; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\Security\Http\Authenticator\Passport\Passport; | ||
/** | ||
* @internal | ||
*/ | ||
trait ForwardCompatAuthenticatorTrait | ||
{ | ||
public function authenticate(Request $request): Passport | ||
{ | ||
return $this->doAuthenticate($request); | ||
} | ||
} | ||
'); | ||
} else { | ||
/** | ||
* @internal | ||
*/ | ||
trait ForwardCompatAuthenticatorTrait | ||
{ | ||
public function authenticate(Request $request): PassportInterface | ||
{ | ||
return $this->doAuthenticate($request); | ||
} | ||
} | ||
} |
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