Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/3.0' into 3.0
Browse files Browse the repository at this point in the history
# Conflicts:
#	Security/Authenticator/Oauth2Authenticator.php
  • Loading branch information
borisDigitalinsure committed Jul 17, 2021
2 parents 565d05f + 87615ae commit 082c365
Show file tree
Hide file tree
Showing 58 changed files with 381 additions and 504 deletions.
8 changes: 0 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ service:
matrix:
fast_finish: true
include:
- php: 7.2
env: SYMFONY_VERSION=4.4.*
- php: 7.3
env: SYMFONY_VERSION=4.4.*
- php: 7.4
env: SYMFONY_VERSION=4.4.*
- php: 8.0
env: SYMFONY_VERSION=4.4.*
- php: 7.2
env: SYMFONY_VERSION=5.3.*
- php: 7.3
Expand Down
47 changes: 8 additions & 39 deletions Controller/AuthorizeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,6 @@ class AuthorizeController
* Thus, this is considered a bad practice to fetch services directly from container.
*
* @todo This controller could be refactored to not rely on so many dependencies
*
* @param RequestStack $requestStack
* @param Form $authorizeForm
* @param AuthorizeFormHandler $authorizeFormHandler
* @param OAuth2 $oAuth2Server
* @param Environment $twig
* @param TokenStorageInterface $tokenStorage
* @param UrlGeneratorInterface $router
* @param ClientManagerInterface $clientManager
* @param EventDispatcherInterface $eventDispatcher
*/
public function __construct(
RequestStack $requestStack,
Expand All @@ -132,8 +122,7 @@ public function __construct(

/**
* Authorize.
* @param Request $request
* @return Response
*
* @throws OAuth2RedirectException
*/
public function authorizeAction(Request $request): Response
Expand All @@ -144,7 +133,7 @@ public function authorizeAction(Request $request): Response
throw new AccessDeniedException('This user does not have access to this section.');
}

if ( ! empty( $request->getSession() ) && true === $request->getSession()->get('_fos_oauth_server.ensure_logout')) {
if (!empty($request->getSession()) && true === $request->getSession()->get('_fos_oauth_server.ensure_logout')) {
$request->getSession()->invalidate(600);
$request->getSession()->set('_fos_oauth_server.ensure_logout', true);
}
Expand Down Expand Up @@ -176,16 +165,9 @@ public function authorizeAction(Request $request): Response
return $this->renderAuthorize($data);
}

/**
* @param UserInterface $user
* @param AuthorizeFormHandler $formHandler
* @param Request $request
*
* @return Response
*/
protected function processSuccess(UserInterface $user, AuthorizeFormHandler $formHandler, Request $request): Response
{
if ( ! empty( $request->getSession() ) && true === $request->getSession()->get('_fos_oauth_server.ensure_logout')) {
if (!empty($request->getSession()) && true === $request->getSession()->get('_fos_oauth_server.ensure_logout')) {
$this->tokenStorage->setToken(null);
$request->getSession()->invalidate();
}
Expand All @@ -211,28 +193,19 @@ protected function processSuccess(UserInterface $user, AuthorizeFormHandler $for

/**
* Generate the redirection url when the authorize is completed.
*
* @param UserInterface $user
*
* @return string
*/
protected function getRedirectionUrl(UserInterface $user)
protected function getRedirectionUrl(UserInterface $user): string
{
return $this->router->generate('fos_oauth_server_profile_show');
}

/**
* @return ClientInterface
*/
protected function getClient(): ClientInterface
{
if (null !== $this->client) {
return $this->client;
}

if (null === $request = $this->getCurrentRequest()) {
throw new NotFoundHttpException('Client not found.');
}
$request = $this->getCurrentRequest();

if (null === $clientId = $request->get('client_id')) {
$formData = $request->get($this->authorizeForm->getName(), []);
Expand All @@ -249,8 +222,7 @@ protected function getClient(): ClientInterface
}

/**
* @param array $data
* @return Response
* @param array<string , mixed> $data Various data to be passed to the twig template
* @throws LoaderError
* @throws RuntimeError
* @throws SyntaxError
Expand All @@ -262,13 +234,10 @@ protected function renderAuthorize(array $data): Response
$data
);

return $response instanceof Response ? $response : new Response($response);
return new Response($response);
}

/**
* @return Request|null
*/
private function getCurrentRequest()
private function getCurrentRequest(): Request
{
$request = $this->requestStack->getCurrentRequest();
if (null === $request) {
Expand Down
10 changes: 1 addition & 9 deletions Controller/TokenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,12 @@ class TokenController
*/
protected $server;

/**
* @param OAuth2 $server
*/
public function __construct(OAuth2 $server)
{
$this->server = $server;
}

/**
* @param Request $request
*
* @return Response
*/
public function tokenAction(Request $request)
public function tokenAction(Request $request): Response
{
try {
return $this->server->grantAccessToken($request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
class GrantExtensionsCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
$storageDefinition = $container->findDefinition('fos_oauth_server.storage');
$className = $container->getParameterBag()->resolveValue($storageDefinition->getClass());
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/Compiler/RequestStackCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class RequestStackCompilerPass implements CompilerPassInterface
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
if ($container->has('request_stack')) {
return;
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/Compiler/TokenStorageCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class TokenStorageCompilerPass implements CompilerPassInterface
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
$definition = $container->getDefinition('fos_oauth_server.security.authentication.listener');

Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Configuration implements ConfigurationInterface
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
/** @var ArrayNodeDefinition $rootNode */
$treeBuilder = new TreeBuilder('fos_oauth_server');
Expand Down
6 changes: 3 additions & 3 deletions Document/AuthCodeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ public function __construct(DocumentManager $dm, $class)
/**
* {@inheritdoc}
*/
public function getClass()
public function getClass(): string
{
return $this->class;
}

/**
* {@inheritdoc}
*/
public function findAuthCodeBy(array $criteria)
public function findAuthCodeBy(array $criteria): ?AuthCodeInterface
{
return $this->repository->findOneBy($criteria);
}
Expand All @@ -83,7 +83,7 @@ public function deleteAuthCode(AuthCodeInterface $authCode)
/**
* {@inheritdoc}
*/
public function deleteExpired()
public function deleteExpired(): int
{
$result = $this
->repository
Expand Down
4 changes: 2 additions & 2 deletions Document/ClientManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ public function __construct(DocumentManager $dm, $class)
/**
* {@inheritdoc}
*/
public function getClass()
public function getClass(): string
{
return $this->class;
}

/**
* {@inheritdoc}
*/
public function findClientBy(array $criteria)
public function findClientBy(array $criteria): ?ClientInterface
{
return $this->repository->findOneBy($criteria);
}
Expand Down
6 changes: 3 additions & 3 deletions Document/TokenManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ public function __construct(DocumentManager $dm, $class)
/**
* {@inheritdoc}
*/
public function getClass()
public function getClass(): string
{
return $this->class;
}

/**
* {@inheritdoc}
*/
public function findTokenBy(array $criteria)
public function findTokenBy(array $criteria): ?TokenInterface
{
return $this->repository->findOneBy($criteria);
}
Expand All @@ -83,7 +83,7 @@ public function deleteToken(TokenInterface $token)
/**
* {@inheritdoc}
*/
public function deleteExpired()
public function deleteExpired(): int
{
$result = $this
->repository
Expand Down
12 changes: 4 additions & 8 deletions Entity/AuthCodeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ class AuthCodeManager extends BaseAuthCodeManager
*/
protected $class;

/**
* @param EntityManagerInterface $em
* @param string $class
*/
public function __construct(EntityManagerInterface $em, $class)
public function __construct(EntityManagerInterface $em, string $class)
{
$this->em = $em;
$this->class = $class;
Expand All @@ -42,15 +38,15 @@ public function __construct(EntityManagerInterface $em, $class)
/**
* {@inheritdoc}
*/
public function getClass()
public function getClass(): string
{
return $this->class;
}

/**
* {@inheritdoc}
*/
public function findAuthCodeBy(array $criteria)
public function findAuthCodeBy(array $criteria): ?AuthCodeInterface
{
return $this->em->getRepository($this->class)->findOneBy($criteria);
}
Expand All @@ -76,7 +72,7 @@ public function deleteAuthCode(AuthCodeInterface $authCode)
/**
* {@inheritdoc}
*/
public function deleteExpired()
public function deleteExpired(): int
{
/** @var \Doctrine\ORM\EntityRepository $repository */
$repository = $this->em->getRepository($this->class);
Expand Down
4 changes: 2 additions & 2 deletions Entity/ClientManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ public function __construct(EntityManagerInterface $em, $class)
/**
* {@inheritdoc}
*/
public function getClass()
public function getClass(): string
{
return $this->class;
}

/**
* {@inheritdoc}
*/
public function findClientBy(array $criteria)
public function findClientBy(array $criteria): ?ClientInterface
{
return $this->repository->findOneBy($criteria);
}
Expand Down
6 changes: 3 additions & 3 deletions Entity/TokenManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ public function __construct(EntityManagerInterface $em, $class)
/**
* {@inheritdoc}
*/
public function getClass()
public function getClass(): string
{
return $this->class;
}

/**
* {@inheritdoc}
*/
public function findTokenBy(array $criteria)
public function findTokenBy(array $criteria): ?TokenInterface
{
return $this->repository->findOneBy($criteria);
}
Expand All @@ -83,7 +83,7 @@ public function deleteToken(TokenInterface $token)
/**
* {@inheritdoc}
*/
public function deleteExpired()
public function deleteExpired(): int
{
$qb = $this->repository->createQueryBuilder('t');
$qb
Expand Down
3 changes: 0 additions & 3 deletions Event/OAuthEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ class OAuthEvent extends Event

/**
* OAuthEvent constructor.
* @param UserInterface $user
* @param ClientInterface $client
* @param bool $isAuthorizedClient
*/
public function __construct(UserInterface $user, ClientInterface $client, bool $isAuthorizedClient = false)
{
Expand Down
3 changes: 1 addition & 2 deletions Form/Handler/AuthorizeFormHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class AuthorizeFormHandler
private $requestStack;

/**
* @param FormInterface $form
* @param Request|RequestStack $requestStack
*/
public function __construct(FormInterface $form, $requestStack = null)
Expand Down Expand Up @@ -94,7 +93,7 @@ public function process()
}

$this->form->handleRequest($request);
if ($this->form->isSubmitted() && ! $this->form->isValid()) {
if ($this->form->isSubmitted() && !$this->form->isValid()) {
return false;
}

Expand Down
4 changes: 0 additions & 4 deletions Form/Model/Authorize.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ class Authorize
*/
public $scope;

/**
* @param bool $accepted
* @param array $query
*/
public function __construct(bool $accepted, array $query = [])
{
foreach ($query as $key => $value) {
Expand Down
4 changes: 2 additions & 2 deletions Model/AuthCodeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ abstract class AuthCodeManager implements AuthCodeManagerInterface
/**
* {@inheritdoc}
*/
public function createAuthCode()
public function createAuthCode(): AuthCodeInterface
{
$class = $this->getClass();

Expand All @@ -28,7 +28,7 @@ public function createAuthCode()
/**
* {@inheritdoc}
*/
public function findAuthCodeByToken($token)
public function findAuthCodeByToken(string $token): ?AuthCodeInterface
{
return $this->findAuthCodeBy(['token' => $token]);
}
Expand Down
Loading

0 comments on commit 082c365

Please sign in to comment.