Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Symfony 4.4.* / 5.0.* #639

Open
wants to merge 63 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
f3cbdb5
Call Form::isSubmitted() before Form::isValid()
scootstah May 24, 2018
fcaa25c
Merge pull request #582 from scootstah/issue/581
GuilhemN Jan 23, 2019
d8717a4
Merge remote-tracking branch 'origin/1.7' into symfony-5
elchris Jan 17, 2020
93a7a5f
initial composer installs to upgraded packages
elchris Jan 17, 2020
078cea7
initial fixes for the test classes to at least compile, so we could a…
elchris Jan 17, 2020
d4f379d
one more batch of Error fixes
elchris Jan 18, 2020
c0612d5
Down to:
elchris Jan 18, 2020
f786aaa
Down to:
elchris Jan 18, 2020
1ae9b70
removed the fall-back to $definition->replaceArgument(0, new Referenc…
elchris Jan 18, 2020
86bd8c5
- undid previous commit because I can't find a graceful way to handle…
elchris Jan 18, 2020
809132f
put back artificial call to hasDefinition to ensure the positive test…
elchris Jan 18, 2020
c02cff9
fixed some warnings against deprecating phpunit methods
elchris Jan 18, 2020
b497745
dealt with assertArraySubset deprecation warnings
elchris Jan 18, 2020
1725798
got rid of deprecated phpunit calls to assertAttribute but in the pro…
elchris Jan 19, 2020
cdd12f1
replaced instance calls to phpunit assert methods with static calls
elchris Jan 19, 2020
5435069
down to 2 warnings. replaced randomResult var with new stdObject inst…
elchris Jan 22, 2020
d7ba5e4
removed reference to SecurityContextInterface because it doesn't exis…
elchris Jan 25, 2020
7277841
Removed token storage compiler pass, which only served to replace mis…
Feb 13, 2020
20c0f59
Updated templating component to Twig only
Feb 13, 2020
24726a3
Clarified no return value from OAuth listener authentication handler
Feb 13, 2020
da7fd54
Merge pull request #1 from iisisrael/symfony-5
elchris Feb 13, 2020
dbf837a
updated CI references and composer packages
elchris Feb 14, 2020
b9e968c
fixes made by php-cs-fixer
elchris Feb 14, 2020
306a769
added phpstan and php-cs-fixer to composer dev, started some cleanups.
elchris Feb 14, 2020
d3ae5e1
cleaned-up some things.
elchris Feb 14, 2020
b292ec1
updated functional tests and fixtures
Feb 14, 2020
f7f9160
Merge pull request #2 from iisisrael/symfony-5
elchris Feb 14, 2020
493b256
removed references to DefinitionDecorator in the test because depreca…
elchris Feb 16, 2020
be25ecc
cleaned LegacyFormHelper.php
elchris Feb 16, 2020
ad3ed82
cleaned AuthorizeFormHandlerTest.php
elchris Feb 16, 2020
5001f50
cleaned-up OAuthStorageTest.php
elchris Feb 16, 2020
744f583
cleaned-up linting
elchris Feb 16, 2020
107e57d
cleaned-up LegacyFormHelper
elchris Feb 16, 2020
b31b767
cleaned OAuthStorageTest.php some more ...
elchris Feb 16, 2020
9e7be74
cleaned TokenTest
elchris Feb 16, 2020
ae1ea29
cleaned Tests/Functional/TestBundle/Entity/User.php
elchris Feb 16, 2020
d63e0bc
cleaned Tests/Functional/TestBundle/Entity/RefreshToken.php
elchris Feb 16, 2020
a60765a
cleaned Tests/Functional/TestBundle/Entity/Client.php
elchris Feb 16, 2020
42512ce
cleaned Tests/Functional/TestBundle/Entity/AuthCode.php
elchris Feb 16, 2020
f8c823f
cleaned Tests/Functional/TestBundle/Entity/AccessToken.php
elchris Feb 16, 2020
899bf6b
cleaned Tests/Functional/BootTest.php
elchris Feb 16, 2020
be5d828
cleaned Tests/Functional/AppKernel.php
elchris Feb 16, 2020
92f085b
cleaned Tests/Form/Type/AuthorizeFormTypeTest.php
elchris Feb 16, 2020
dbf2ebf
cleaned Tests/Form/Handler/AuthorizeFormHandlerTest.php
elchris Feb 16, 2020
3338833
cleaned Tests/FOSOAuthServerBundleTest.php
elchris Feb 16, 2020
c0778a9
cleaned Tests/Entity/TokenManagerTest.php
elchris Feb 16, 2020
1e7dc5a
cleaned Tests/Entity/ClientManagerTest.php
elchris Feb 16, 2020
470ebca
cleaned Tests/Document/TokenManagerTest.php
elchris Feb 16, 2020
aff92f8
cleaned Tests/Document/ClientManagerTest.php
elchris Feb 16, 2020
6094298
cleaned Tests/DependencyInjection/FOSOAuthServerExtensionTest.php
elchris Feb 16, 2020
ce74ed3
cleaned Tests/DependencyInjection/Compiler/RequestStackCompilerPassTe…
elchris Feb 16, 2020
8631eb2
cleaned Tests/DependencyInjection/Compiler/GrantExtensionsCompilerPas…
elchris Feb 16, 2020
ab6fa2d
cleaned Tests/Command/CleanCommandTest.php
elchris Feb 16, 2020
ce913dc
Removed getter methods in preference of reflection property when excl…
Feb 19, 2020
b42e554
Merge pull request #3 from iisisrael/symfony-5
elchris Feb 19, 2020
2599205
Added Mongo functional tests with identified fixes.
Feb 19, 2020
2bfb4a6
Code style fixes
Feb 19, 2020
e81ef7b
Fixed entity manager fixture return mock values.
Feb 19, 2020
1d66023
Allowed for local phpstan configuration override.
Feb 19, 2020
a149658
Restored OAuthListener void return.
Feb 19, 2020
ec9ad9f
Fixed throwing an error with anonymous users
patrickbussmann Feb 19, 2020
6c7e091
Merge pull request #4 from iisisrael/symfony-5
elchris Feb 24, 2020
092cea1
Merge pull request #5 from patrickbussmann/symfony-5-anonymous-access
elchris Feb 24, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
phpstan.neon
phpunit.xml
Tests/autoload.php
var/
vendor/
Propel/om/
Propel/map/
composer.lock
.php_cs.cache
.phpunit.result.cache
15 changes: 10 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ language: php

sudo: true
php:
- 7.1
- 7.2

service:
Expand All @@ -12,12 +11,18 @@ service:
matrix:
fast_finish: true
include:
- php: 7.1
env: SYMFONY_VERSION=3.4.*
- php: 7.2
env: SYMFONY_VERSION=4.0.*
env: SYMFONY_VERSION=4.4.*
- php: 7.2
env: SYMFONY_VERSION=4.0.* DEPENDENCIES=beta
env: SYMFONY_VERSION=5.0.*
- php: 7.3
env: SYMFONY_VERSION=4.4.*
- php: 7.3
env: SYMFONY_VERSION=5.0.*
- php: 7.4
env: SYMFONY_VERSION=4.4.*
- php: 7.4
env: SYMFONY_VERSION=5.0.*

cache:
directories:
Expand Down
21 changes: 17 additions & 4 deletions Command/CleanCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,20 @@

class CleanCommand extends Command
{
/** @var TokenManagerInterface */
private $accessTokenManager;

/** @var TokenManagerInterface */
private $refreshTokenManager;

/** @var AuthCodeManagerInterface */
private $authCodeManager;

public function __construct(
TokenManagerInterface $accessTokenManager,
TokenManagerInterface $refreshTokenManager,
AuthCodeManagerInterface $authCodeManager)
{
AuthCodeManagerInterface $authCodeManager
) {
parent::__construct();

$this->accessTokenManager = $accessTokenManager;
Expand All @@ -40,7 +45,7 @@ public function __construct(
/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
parent::configure();

Expand All @@ -63,7 +68,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
foreach ([$this->accessTokenManager, $this->refreshTokenManager, $this->authCodeManager] as $service) {
$result = $service->deleteExpired();
$output->writeln(sprintf('Removed <info>%d</info> items from <comment>%s</comment> storage.', $result, get_class($service)));
$output->writeln(
sprintf(
'Removed <info>%d</info> items from <comment>%s</comment> storage.',
$result,
get_class($service)
)
);
}

return 0;
}
}
3 changes: 2 additions & 1 deletion Command/CreateClientCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

class CreateClientCommand extends Command
{
/** @var ClientManagerInterface */
private $clientManager;

public function __construct(ClientManagerInterface $clientManager)
Expand All @@ -34,7 +35,7 @@ public function __construct(ClientManagerInterface $clientManager)
/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
parent::configure();

Expand Down
96 changes: 29 additions & 67 deletions Controller/AuthorizeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use FOS\OAuthServerBundle\Model\ClientManagerInterface;
use OAuth2\OAuth2;
use OAuth2\OAuth2ServerException;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use RuntimeException;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Form\Form;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -31,6 +31,7 @@
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Core\User\UserInterface;
use Twig\Environment;

/**
* Controller handling basic authorization.
Expand Down Expand Up @@ -65,9 +66,9 @@ class AuthorizeController
private $oAuth2Server;

/**
* @var EngineInterface
* @var Environment
*/
private $templating;
private $twig;

/**
* @var RequestStack
Expand All @@ -89,11 +90,6 @@ class AuthorizeController
*/
private $clientManager;

/**
* @var string
*/
private $templateEngineType;

/**
* @var EventDispatcherInterface
*/
Expand All @@ -105,47 +101,32 @@ class AuthorizeController
*
* @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 EngineInterface $templating
* @param TokenStorageInterface $tokenStorage
* @param UrlGeneratorInterface $router
* @param ClientManagerInterface $clientManager
* @param EventDispatcherInterface $eventDispatcher
* @param SessionInterface $session
* @param string $templateEngineType
* @param SessionInterface $session
*/
public function __construct(
RequestStack $requestStack,
Form $authorizeForm,
AuthorizeFormHandler $authorizeFormHandler,
OAuth2 $oAuth2Server,
EngineInterface $templating,
Environment $twig,
TokenStorageInterface $tokenStorage,
UrlGeneratorInterface $router,
ClientManagerInterface $clientManager,
EventDispatcherInterface $eventDispatcher,
SessionInterface $session = null,
$templateEngineType = 'twig'
SessionInterface $session = null
) {
$this->requestStack = $requestStack;
$this->session = $session;
$this->authorizeForm = $authorizeForm;
$this->authorizeFormHandler = $authorizeFormHandler;
$this->oAuth2Server = $oAuth2Server;
$this->templating = $templating;
$this->twig = $twig;
$this->tokenStorage = $tokenStorage;
$this->router = $router;
$this->clientManager = $clientManager;
$this->templateEngineType = $templateEngineType;
$this->eventDispatcher = $eventDispatcher;
}

/**
* Authorize.
*/
public function authorizeAction(Request $request)
{
$user = $this->tokenStorage->getToken()->getUser();
Expand All @@ -164,8 +145,11 @@ public function authorizeAction(Request $request)

/** @var OAuthEvent $event */
$event = $this->eventDispatcher->dispatch(
OAuthEvent::PRE_AUTHORIZATION_PROCESS,
new OAuthEvent($user, $this->getClient())
new OAuthEvent(
$user,
$this->getClient()
),
OAuthEvent::PRE_AUTHORIZATION_PROCESS
);

if ($event->isAuthorizedClient()) {
Expand All @@ -183,26 +167,25 @@ public function authorizeAction(Request $request)
'client' => $this->getClient(),
];

return $this->renderAuthorize($data, $this->templating, $this->templateEngineType);
return new Response(
$this->twig->render('@FOSOAuthServer/Authorize/authorize.html.twig', $data),
Response::HTTP_OK
);
}

/**
* @param UserInterface $user
* @param AuthorizeFormHandler $formHandler
* @param Request $request
*
* @return Response
*/
protected function processSuccess(UserInterface $user, AuthorizeFormHandler $formHandler, Request $request)
{
protected function processSuccess(
UserInterface $user,
AuthorizeFormHandler $formHandler,
Request $request
): ?Response {
if ($this->session && true === $this->session->get('_fos_oauth_server.ensure_logout')) {
$this->tokenStorage->setToken(null);
$this->session->invalidate();
}

$this->eventDispatcher->dispatch(
OAuthEvent::POST_AUTHORIZATION_PROCESS,
new OAuthEvent($user, $this->getClient(), $formHandler->isAccepted())
new OAuthEvent($user, $this->getClient(), $formHandler->isAccepted()),
OAuthEvent::POST_AUTHORIZATION_PROCESS
);

$formName = $this->authorizeForm->getName();
Expand All @@ -221,20 +204,13 @@ 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()
protected function getClient(): ClientInterface
{
if (null !== $this->client) {
return $this->client;
Expand All @@ -246,7 +222,7 @@ protected function getClient()

if (null === $clientId = $request->get('client_id')) {
$formData = $request->get($this->authorizeForm->getName(), []);
$clientId = isset($formData['client_id']) ? $formData['client_id'] : null;
$clientId = $formData['client_id'] ?? null;
}

$this->client = $this->clientManager->findClientByPublicId($clientId);
Expand All @@ -258,25 +234,11 @@ protected function getClient()
return $this->client;
}

/**
* @throws \RuntimeException
*/
protected function renderAuthorize(array $data, EngineInterface $engine, string $engineType): Response
{
return $engine->renderResponse(
'@FOSOAuthServer/Authorize/authorize.html.'.$engineType,
$data
);
}

/**
* @return null|Request
*/
private function getCurrentRequest()
private function getCurrentRequest(): ?Request
{
$request = $this->requestStack->getCurrentRequest();
if (null === $request) {
throw new \RuntimeException('No current request.');
throw new RuntimeException('No current request.');
}

return $request;
Expand Down
5 changes: 0 additions & 5 deletions Controller/TokenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +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)
Expand Down
8 changes: 5 additions & 3 deletions DependencyInjection/Compiler/GrantExtensionsCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

namespace FOS\OAuthServerBundle\DependencyInjection\Compiler;

use FOS\OAuthServerBundle\Storage\GrantExtensionDispatcherInterface;
use ReflectionClass;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
Expand All @@ -23,12 +25,12 @@
*/
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());
$storageClass = new \ReflectionClass($className);
if (!$storageClass->implementsInterface('FOS\OAuthServerBundle\Storage\GrantExtensionDispatcherInterface')) {
$storageClass = new ReflectionClass($className);
if (!$storageClass->implementsInterface(GrantExtensionDispatcherInterface::class)) {
return;
}

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
Loading