From 1c4691c96e5e9e09d42a64ea093cb3ed09a1004b Mon Sep 17 00:00:00 2001 From: Klapaudius Date: Thu, 13 Jan 2022 11:35:09 +0100 Subject: [PATCH] Symfony 5.4 deprecation warnings free Symfony 5.4 force the use of native return type declarations --- .../FOSOAuthServerExtension.php | 2 +- .../Security/Factory/OAuthFactory.php | 39 +++---------------- FOSOAuthServerBundle.php | 2 +- Model/Client.php | 20 +++++----- Model/Token.php | 13 ++++--- 5 files changed, 24 insertions(+), 52 deletions(-) diff --git a/DependencyInjection/FOSOAuthServerExtension.php b/DependencyInjection/FOSOAuthServerExtension.php index 09250216..7f2f56eb 100644 --- a/DependencyInjection/FOSOAuthServerExtension.php +++ b/DependencyInjection/FOSOAuthServerExtension.php @@ -108,7 +108,7 @@ public function load(array $configs, ContainerBuilder $container) /** * {@inheritdoc} */ - public function getAlias() + public function getAlias(): string { return 'fos_oauth_server'; } diff --git a/DependencyInjection/Security/Factory/OAuthFactory.php b/DependencyInjection/Security/Factory/OAuthFactory.php index 7af5f059..ed8fe939 100644 --- a/DependencyInjection/Security/Factory/OAuthFactory.php +++ b/DependencyInjection/Security/Factory/OAuthFactory.php @@ -14,7 +14,6 @@ namespace FOS\OAuthServerBundle\DependencyInjection\Security\Factory; 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\Argument\ServiceClosureArgument; use Symfony\Component\DependencyInjection\ChildDefinition; @@ -26,9 +25,9 @@ * * @author Arnaud Le Blanc */ -class OAuthFactory implements SecurityFactoryInterface, AuthenticatorFactoryInterface +class OAuthFactory implements AuthenticatorFactoryInterface { - public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId) + public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId): string { $authenticatorId = 'security.authenticator.oauth2.'.$firewallName; $firewallEventDispatcherId = 'security.event_dispatcher.'.$firewallName; @@ -70,43 +69,15 @@ public function createAuthenticator(ContainerBuilder $container, string $firewal return $authenticatorId; } - /** - * {@inheritdoc} - */ - public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint) - { - // NOTE: done like this to avoid PHPStan complaining about a missing class for both Symfony v3 and Symfony v4 - $definitionDecorator = 'Symfony\\Component\\DependencyInjection\\DefinitionDecorator'; - $childDefinition = 'Symfony\\Component\\DependencyInjection\\ChildDefinition'; - $definitionClass = $childDefinition; - if (class_exists($definitionDecorator)) { - $definitionClass = $definitionDecorator; - } - - $providerId = 'security.authentication.provider.fos_oauth_server.'.$id; - $container - ->setDefinition($providerId, new $definitionClass('fos_oauth_server.security.authentication.provider')) - ->replaceArgument(0, new Reference($userProvider)) - ; - - $listenerId = 'security.authentication.listener.fos_oauth_server.'.$id; - $container->setDefinition($listenerId, new $definitionClass('fos_oauth_server.security.authentication.listener')); - - return [$providerId, $listenerId, 'fos_oauth_server.security.entry_point']; - } - - /** - * {@inheritdoc} - */ - public function getPosition() + public function getPriority(): int { - return 'pre_auth'; + return 0; } /** * {@inheritdoc} */ - public function getKey() + public function getKey(): string { return 'fos_oauth'; } diff --git a/FOSOAuthServerBundle.php b/FOSOAuthServerBundle.php index c6ba0f9f..d1e56f84 100644 --- a/FOSOAuthServerBundle.php +++ b/FOSOAuthServerBundle.php @@ -35,7 +35,7 @@ public function build(ContainerBuilder $container) /** @var SecurityExtension $extension */ $extension = $container->getExtension('security'); - $extension->addSecurityListenerFactory(new OAuthFactory()); + $extension->addAuthenticatorFactory(new OAuthFactory()); $container->addCompilerPass(new GrantExtensionsCompilerPass()); $container->addCompilerPass(new TokenStorageCompilerPass()); diff --git a/Model/Client.php b/Model/Client.php index fed5fc33..356ac6d5 100644 --- a/Model/Client.php +++ b/Model/Client.php @@ -26,22 +26,22 @@ class Client implements ClientInterface /** * @var string */ - protected $randomId; + protected string $randomId; /** * @var string */ - protected $secret; + protected string $secret; /** * @var array */ - protected $redirectUris = []; + protected array $redirectUris = []; /** * @var array */ - protected $allowedGrantTypes = []; + protected array $allowedGrantTypes = []; public function __construct() { @@ -75,7 +75,7 @@ public function getRandomId(): string /** * {@inheritdoc} */ - public function getPublicId() + public function getPublicId(): string { return sprintf('%s_%s', $this->getId(), $this->getRandomId()); } @@ -115,7 +115,7 @@ public function setRedirectUris(array $redirectUris) /** * {@inheritdoc} */ - public function getRedirectUris() + public function getRedirectUris(): array { return $this->redirectUris; } @@ -136,17 +136,17 @@ public function getAllowedGrantTypes(): array return $this->allowedGrantTypes; } - public function getRoles() + public function getRoles(): array { return [ 'ROLE_USER' ]; } - public function getPassword() + public function getPassword(): string { return $this->getSecret(); } - public function getSalt() + public function getSalt(): ?string { // Will use auto salt system } @@ -156,7 +156,7 @@ public function eraseCredentials() // nothind to erase } - public function getUsername() + public function getUsername(): string { return $this->getRandomId(); } diff --git a/Model/Token.php b/Model/Token.php index bd7df3b1..d743ac62 100644 --- a/Model/Token.php +++ b/Model/Token.php @@ -30,7 +30,7 @@ class Token implements TokenInterface /** * @var string */ - protected $token; + protected string $token; /** * @var int @@ -55,7 +55,7 @@ public function getId() /** * {@inheritdoc} */ - public function getClientId() + public function getClientId(): string { return $this->getClient()->getPublicId(); } @@ -79,7 +79,7 @@ public function getExpiresAt(): int /** * {@inheritdoc} */ - public function getExpiresIn() + public function getExpiresIn(): int { if ($this->expiresAt) { return $this->expiresAt - time(); @@ -91,7 +91,7 @@ public function getExpiresIn() /** * {@inheritdoc} */ - public function hasExpired() + public function hasExpired(): bool { if ($this->expiresAt) { return time() > $this->expiresAt; @@ -111,7 +111,7 @@ public function setToken($token) /** * {@inheritdoc} */ - public function getToken() + public function getToken(): string { return $this->token; } @@ -127,7 +127,7 @@ public function setScope($scope) /** * {@inheritdoc} */ - public function getScope() + public function getScope(): ?string { return $this->scope; } @@ -150,6 +150,7 @@ public function getUser(): ?UserInterface /** * {@inheritdoc} + * @return mixed */ public function getData() {