Skip to content

Commit

Permalink
Fix some of the Symfony reported deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
X-Coder264 committed Jun 29, 2023
1 parent 55fe5b9 commit fd88cd8
Show file tree
Hide file tree
Showing 24 changed files with 97 additions and 75 deletions.
2 changes: 1 addition & 1 deletion DBAL/Type/Grant.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class Grant extends ImplodedArray
/**
* {@inheritdoc}
*/
public function getName()
public function getName(): string
{
return self::NAME;
}
Expand Down
12 changes: 6 additions & 6 deletions DBAL/Type/ImplodedArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ abstract class ImplodedArray extends TextType
/**
* {@inheritdoc}
*/
public function convertToDatabaseValue($value, AbstractPlatform $platform)
public function convertToDatabaseValue($value, AbstractPlatform $platform): ?string
{
if (!\is_array($value)) {
throw new \LogicException('This type can only be used in combination with arrays.');
Expand All @@ -37,7 +37,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)
/**
* {@inheritdoc}
*/
public function convertToPHPValue($value, AbstractPlatform $platform)
public function convertToPHPValue($value, AbstractPlatform $platform): array
{
if (null === $value) {
return [];
Expand All @@ -51,17 +51,17 @@ public function convertToPHPValue($value, AbstractPlatform $platform)
/**
* {@inheritdoc}
*/
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
$fieldDeclaration['length'] = 65535;
$column['length'] = 65535;

return parent::getSQLDeclaration($fieldDeclaration, $platform);
return parent::getSQLDeclaration($column, $platform);
}

/**
* {@inheritdoc}
*/
public function requiresSQLCommentHint(AbstractPlatform $platform)
public function requiresSQLCommentHint(AbstractPlatform $platform): bool
{
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion DBAL/Type/RedirectUri.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class RedirectUri extends ImplodedArray
/**
* {@inheritdoc}
*/
public function getName()
public function getName(): string
{
return self::NAME;
}
Expand Down
2 changes: 1 addition & 1 deletion DBAL/Type/Scope.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class Scope extends ImplodedArray
/**
* {@inheritdoc}
*/
public function getName()
public function getName(): string
{
return self::NAME;
}
Expand Down
6 changes: 3 additions & 3 deletions DependencyInjection/Security/OAuth2Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class OAuth2Factory implements SecurityFactoryInterface
/**
* {@inheritdoc}
*/
public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint)
public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint): array
{
$providerId = 'security.authentication.provider.oauth2.' . $id;
$container
Expand All @@ -37,15 +37,15 @@ public function create(ContainerBuilder $container, $id, $config, $userProvider,
/**
* {@inheritdoc}
*/
public function getPosition()
public function getPosition(): string
{
return 'pre_auth';
}

/**
* {@inheritdoc}
*/
public function getKey()
public function getKey(): string
{
return 'oauth2';
}
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/TrikoderOAuth2Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function load(array $configs, ContainerBuilder $container)
/**
* {@inheritdoc}
*/
public function getAlias()
public function getAlias(): string
{
return 'trikoder_oauth2';
}
Expand Down
4 changes: 2 additions & 2 deletions League/Repository/AccessTokenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct(
/**
* {@inheritdoc}
*/
public function getNewToken(ClientEntityInterface $clientEntity, array $scopes, $userIdentifier = null)
public function getNewToken(ClientEntityInterface $clientEntity, array $scopes, $userIdentifier = null): AccessTokenEntityInterface
{
$accessToken = new AccessTokenEntity();
$accessToken->setClient($clientEntity);
Expand Down Expand Up @@ -92,7 +92,7 @@ public function revokeAccessToken($tokenId)
/**
* {@inheritdoc}
*/
public function isAccessTokenRevoked($tokenId)
public function isAccessTokenRevoked($tokenId): bool
{
$accessToken = $this->accessTokenManager->find($tokenId);

Expand Down
4 changes: 2 additions & 2 deletions League/Repository/AuthCodeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct(
/**
* {@inheritdoc}
*/
public function getNewAuthCode()
public function getNewAuthCode(): AuthCodeEntityInterface
{
return new AuthCode();
}
Expand Down Expand Up @@ -83,7 +83,7 @@ public function revokeAuthCode($codeId)
/**
* {@inheritdoc}
*/
public function isAuthCodeRevoked($codeId)
public function isAuthCodeRevoked($codeId): bool
{
$authorizationCode = $this->authorizationCodeManager->find($codeId);

Expand Down
7 changes: 4 additions & 3 deletions League/Repository/ClientRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

namespace Trikoder\Bundle\OAuth2Bundle\League\Repository;

use League\OAuth2\Server\Entities\ClientEntityInterface;
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
use Trikoder\Bundle\OAuth2Bundle\League\Entity\Client as ClientEntity;
use Trikoder\Bundle\OAuth2Bundle\Manager\ClientManagerInterface;
use Trikoder\Bundle\OAuth2Bundle\Model\Client as ClientModel;
use Trikoder\Bundle\OAuth2Bundle\Model\ClientInterface as ClientModel;

final class ClientRepository implements ClientRepositoryInterface
{
Expand All @@ -24,7 +25,7 @@ public function __construct(ClientManagerInterface $clientManager)
/**
* {@inheritdoc}
*/
public function getClientEntity($clientIdentifier)
public function getClientEntity($clientIdentifier): ?ClientEntityInterface
{
$client = $this->clientManager->find($clientIdentifier);

Expand All @@ -38,7 +39,7 @@ public function getClientEntity($clientIdentifier)
/**
* {@inheritdoc}
*/
public function validateClient($clientIdentifier, $clientSecret, $grantType)
public function validateClient($clientIdentifier, $clientSecret, $grantType): bool
{
$client = $this->clientManager->find($clientIdentifier);

Expand Down
4 changes: 2 additions & 2 deletions League/Repository/RefreshTokenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(
/**
* {@inheritdoc}
*/
public function getNewRefreshToken()
public function getNewRefreshToken(): RefreshTokenEntityInterface
{
return new RefreshTokenEntity();
}
Expand Down Expand Up @@ -75,7 +75,7 @@ public function revokeRefreshToken($tokenId)
/**
* {@inheritdoc}
*/
public function isRefreshTokenRevoked($tokenId)
public function isRefreshTokenRevoked($tokenId): bool
{
$refreshToken = $this->refreshTokenManager->find($tokenId);

Expand Down
9 changes: 5 additions & 4 deletions League/Repository/ScopeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
namespace Trikoder\Bundle\OAuth2Bundle\League\Repository;

use League\OAuth2\Server\Entities\ClientEntityInterface;
use League\OAuth2\Server\Entities\ScopeEntityInterface;
use League\OAuth2\Server\Exception\OAuthServerException;
use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Trikoder\Bundle\OAuth2Bundle\Converter\ScopeConverterInterface;
use Trikoder\Bundle\OAuth2Bundle\Event\ScopeResolveEvent;
use Trikoder\Bundle\OAuth2Bundle\Manager\ClientManagerInterface;
use Trikoder\Bundle\OAuth2Bundle\Manager\ScopeManagerInterface;
use Trikoder\Bundle\OAuth2Bundle\Model\Client as ClientModel;
use Trikoder\Bundle\OAuth2Bundle\Model\ClientInterface as ClientModel;
use Trikoder\Bundle\OAuth2Bundle\Model\Grant as GrantModel;
use Trikoder\Bundle\OAuth2Bundle\Model\Scope as ScopeModel;
use Trikoder\Bundle\OAuth2Bundle\Model\ScopeInterface as ScopeModel;
use Trikoder\Bundle\OAuth2Bundle\OAuth2Events;

final class ScopeRepository implements ScopeRepositoryInterface
Expand Down Expand Up @@ -54,7 +55,7 @@ public function __construct(
/**
* {@inheritdoc}
*/
public function getScopeEntityByIdentifier($identifier)
public function getScopeEntityByIdentifier($identifier): ?ScopeEntityInterface
{
$scope = $this->scopeManager->find($identifier);

Expand All @@ -73,7 +74,7 @@ public function finalizeScopes(
$grantType,
ClientEntityInterface $clientEntity,
$userIdentifier = null
) {
): array {
$client = $this->clientManager->find($clientEntity->getIdentifier());

$scopes = $this->setupScopes($client, $this->scopeConverter->toDomainArray($scopes));
Expand Down
3 changes: 2 additions & 1 deletion League/Repository/UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Trikoder\Bundle\OAuth2Bundle\League\Repository;

use League\OAuth2\Server\Entities\ClientEntityInterface;
use League\OAuth2\Server\Entities\UserEntityInterface;
use League\OAuth2\Server\Repositories\UserRepositoryInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Trikoder\Bundle\OAuth2Bundle\Converter\UserConverterInterface;
Expand Down Expand Up @@ -48,7 +49,7 @@ public function getUserEntityByUserCredentials(
$password,
$grantType,
ClientEntityInterface $clientEntity
) {
): ?UserEntityInterface {
$client = $this->clientManager->find($clientEntity->getIdentifier());

$event = $this->eventDispatcher->dispatch(
Expand Down
15 changes: 10 additions & 5 deletions Security/Authentication/Provider/OAuth2Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Trikoder\Bundle\OAuth2Bundle\Security\Authentication\Token\OAuth2Token;
use Trikoder\Bundle\OAuth2Bundle\Security\Authentication\Token\OAuth2TokenFactory;
use Trikoder\Bundle\OAuth2Bundle\Security\User\NullUser;

final class OAuth2Provider implements AuthenticationProviderInterface
{
Expand Down Expand Up @@ -51,7 +52,7 @@ public function __construct(
/**
* {@inheritdoc}
*/
public function authenticate(TokenInterface $token)
public function authenticate(TokenInterface $token): TokenInterface
{
if (!$this->supports($token)) {
throw new \RuntimeException(sprintf('This authentication provider can only handle tokes of type \'%s\'.', OAuth2Token::class));
Expand All @@ -78,21 +79,25 @@ public function authenticate(TokenInterface $token)
/**
* {@inheritdoc}
*/
public function supports(TokenInterface $token)
public function supports(TokenInterface $token): bool
{
return $token instanceof OAuth2Token && $this->providerKey === $token->getProviderKey();
}

private function getAuthenticatedUser(string $userIdentifier): ?UserInterface
private function getAuthenticatedUser(string $userIdentifier): UserInterface
{
if ('' === $userIdentifier) {
/*
* If the identifier is an empty string, that means that the
* access token isn't bound to a user defined in the system.
*/
return null;
return new NullUser();
}

return $this->userProvider->loadUserByUsername($userIdentifier);
if (!method_exists($this->userProvider, 'loadUserByIdentifier')) {
return $this->userProvider->loadUserByUsername($userIdentifier);
}

return $this->userProvider->loadUserByIdentifier($userIdentifier);
}
}
2 changes: 1 addition & 1 deletion Security/Authentication/Token/OAuth2Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct(
/**
* {@inheritdoc}
*/
public function getCredentials()
public function getCredentials(): mixed
{
return $this->getAttribute('server_request')->getAttribute('oauth_access_token_id');
}
Expand Down
2 changes: 1 addition & 1 deletion Security/EntryPoint/OAuth2EntryPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class OAuth2EntryPoint implements AuthenticationEntryPointInterface
/**
* {@inheritdoc}
*/
public function start(Request $request, ?AuthenticationException $authException = null)
public function start(Request $request, ?AuthenticationException $authException = null): Response
{
$exception = new UnauthorizedHttpException('Bearer');

Expand Down
18 changes: 12 additions & 6 deletions Security/Guard/Authenticator/OAuth2Authenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function supports(Request $request): bool
return str_starts_with($request->headers->get('Authorization', ''), 'Bearer ');
}

public function getCredentials(Request $request)
public function getCredentials(Request $request): mixed
{
$psr7Request = $this->httpMessageFactory->createRequest($request);

Expand All @@ -65,19 +65,25 @@ public function getCredentials(Request $request)

public function getUser($userIdentifier, UserProviderInterface $userProvider): UserInterface
{
return '' === $userIdentifier ? new NullUser() : $userProvider->loadUserByUsername($userIdentifier);
if ('' === $userIdentifier) {
return new NullUser();
}

if (!method_exists($userProvider, 'loadUserByIdentifier')) {
return $userProvider->loadUserByUsername($userIdentifier);
}

return $userProvider->loadUserByIdentifier($userIdentifier);
}

public function checkCredentials($token, UserInterface $user): bool
public function checkCredentials($credentials, UserInterface $user): bool
{
return true;
}

public function createAuthenticatedToken(UserInterface $user, $providerKey): OAuth2Token
{
$tokenUser = $user instanceof NullUser ? null : $user;

$oauth2Token = $this->oauth2TokenFactory->createOAuth2Token($this->psr7Request, $tokenUser, $providerKey);
$oauth2Token = $this->oauth2TokenFactory->createOAuth2Token($this->psr7Request, $user, $providerKey);

if (!$this->isAccessToRouteGranted($oauth2Token)) {
throw InsufficientScopesException::create($oauth2Token);
Expand Down
9 changes: 7 additions & 2 deletions Security/User/NullUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,21 @@
*/
final class NullUser implements UserInterface
{
public function getUsername(): string
public function getUserIdentifier(): string
{
return '';
}

public function getPassword(): string
public function getUsername(): string
{
return '';
}

public function getPassword(): ?string
{
return null;
}

public function getSalt(): ?string
{
return null;
Expand Down
8 changes: 4 additions & 4 deletions Tests/Fixtures/FakeGrant.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
namespace Trikoder\Bundle\OAuth2Bundle\Tests\Fixtures;

use League\OAuth2\Server\Grant\AbstractGrant;
use League\OAuth2\Server\ResponseTypes\BearerTokenResponse;
use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface;
use Nyholm\Psr7\Response;
use Psr\Http\Message\ServerRequestInterface;
use Trikoder\Bundle\OAuth2Bundle\League\AuthorizationServer\GrantTypeInterface;

final class FakeGrant extends AbstractGrant implements GrantTypeInterface
{
public function getIdentifier()
public function getIdentifier(): string
{
return 'fake_grant';
}

public function respondToAccessTokenRequest(ServerRequestInterface $request, ResponseTypeInterface $responseType, \DateInterval $accessTokenTTL)
public function respondToAccessTokenRequest(ServerRequestInterface $request, ResponseTypeInterface $responseType, \DateInterval $accessTokenTTL): ResponseTypeInterface
{
return new Response();
return new BearerTokenResponse();
}

public function getAccessTokenTTL(): ?\DateInterval
Expand Down
Loading

0 comments on commit fd88cd8

Please sign in to comment.