diff --git a/.gitignore b/.gitignore index f878b453..0057423a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ /Tests/Build/.phpunit.result.cache /Libraries/vendor /composer.lock +/rector.php +/.idea \ No newline at end of file diff --git a/Classes/Command/CleanUpCommand.php b/Classes/Command/CleanUpCommand.php index 16d4a61c..16b8906e 100644 --- a/Classes/Command/CleanUpCommand.php +++ b/Classes/Command/CleanUpCommand.php @@ -11,15 +11,15 @@ * Florian Wessels , Leuchtfeuer Digital Marketing */ -namespace Bitmotion\Auth0\Command; +namespace Leuchtfeuer\Auth0\Command; use Auth0\SDK\Exception\ArgumentException; use Auth0\SDK\Exception\NetworkException; -use Bitmotion\Auth0\Domain\Transfer\EmAuth0Configuration; -use Bitmotion\Auth0\Factory\ApplicationFactory; use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\Exception; use GuzzleHttp\Exception\GuzzleException; +use Leuchtfeuer\Auth0\Domain\Transfer\EmAuth0Configuration; +use Leuchtfeuer\Auth0\Factory\ApplicationFactory; use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerAwareTrait; use Symfony\Component\Console\Command\Command; diff --git a/Classes/Configuration/Auth0Configuration.php b/Classes/Configuration/Auth0Configuration.php index 255111d4..1831e69b 100644 --- a/Classes/Configuration/Auth0Configuration.php +++ b/Classes/Configuration/Auth0Configuration.php @@ -9,9 +9,9 @@ * Florian Wessels , Leuchtfeuer Digital Marketing */ -namespace Bitmotion\Auth0\Configuration; +namespace Leuchtfeuer\Auth0\Configuration; -use Bitmotion\Auth0\Factory\ConfigurationFactory; +use Leuchtfeuer\Auth0\Factory\ConfigurationFactory; use Symfony\Component\Yaml\Yaml; use TYPO3\CMS\Core\Configuration\Loader\YamlFileLoader; use TYPO3\CMS\Core\Core\Environment; diff --git a/Classes/Controller/ApplicationController.php b/Classes/Controller/ApplicationController.php index 8747c0d6..1d89b50b 100644 --- a/Classes/Controller/ApplicationController.php +++ b/Classes/Controller/ApplicationController.php @@ -9,10 +9,12 @@ * Florian Wessels , Leuchtfeuer Digital Marketing */ -namespace Bitmotion\Auth0\Controller; +namespace Leuchtfeuer\Auth0\Controller; -use Bitmotion\Auth0\Domain\Model\Application; -use Bitmotion\Auth0\Domain\Transfer\EmAuth0Configuration; +use Leuchtfeuer\Auth0\Domain\Model\Application; +use Leuchtfeuer\Auth0\Domain\Transfer\EmAuth0Configuration; +use Leuchtfeuer\Auth0\Utility\ModeUtility; +use Psr\Http\Message\ResponseInterface; use TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException; use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; @@ -23,27 +25,32 @@ class ApplicationController extends BackendController /** * @throws RouteNotFoundException */ - public function listAction(): void + public function listAction(): ResponseInterface { + $moduleTemplate = $this->initView(); $pid = $this->getStoragePage(); $this->view->assignMultiple([ 'applications' => $this->applicationRepository->findAll(), 'pid' => $pid, 'directory' => BackendUtility::getRecord('pages', $pid), - 'returnUrl' => $this->getModuleUrl(false), ]); + if (!ModeUtility::isTYPO3V12()) { + $this->view->assign('returnUrl', $this->getModuleUrl(false)); + } + $moduleTemplate->setContent($this->view->render()); + + return $this->htmlResponse($moduleTemplate->renderContent()); } /** - * @param Application $application - * * @throws StopActionException */ - public function deleteAction(Application $application): void + public function deleteAction(Application $application): ResponseInterface { $this->applicationRepository->remove($application); $this->addFlashMessage($this->getTranslation('message.application.deleted.text'), $this->getTranslation('message.application.deleted.title')); - $this->redirect('list'); + + return $this->redirect('list'); } protected function getStoragePage(): int diff --git a/Classes/Controller/BackendController.php b/Classes/Controller/BackendController.php index 9b245359..36e0a5ce 100644 --- a/Classes/Controller/BackendController.php +++ b/Classes/Controller/BackendController.php @@ -9,54 +9,62 @@ * Florian Wessels , Leuchtfeuer Digital Marketing */ -namespace Bitmotion\Auth0\Controller; +namespace Leuchtfeuer\Auth0\Controller; -use Bitmotion\Auth0\Domain\Repository\ApplicationRepository; +use Leuchtfeuer\Auth0\Domain\Repository\ApplicationRepository; +use Psr\Http\Message\ResponseInterface; use TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException; use TYPO3\CMS\Backend\Routing\UriBuilder as BackendUriBuilder; use TYPO3\CMS\Backend\Template\Components\ButtonBar; -use TYPO3\CMS\Backend\View\BackendTemplateView; +use TYPO3\CMS\Backend\Template\ModuleTemplate; +use TYPO3\CMS\Backend\Template\ModuleTemplateFactory; use TYPO3\CMS\Core\Imaging\Icon; +use TYPO3\CMS\Core\Imaging\IconFactory; use TYPO3\CMS\Core\Localization\LanguageService; use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; -use TYPO3\CMS\Extbase\Mvc\View\ViewInterface; use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder; class BackendController extends ActionController { - /** - * @var BackendTemplateView - */ - protected $view; - - protected $defaultViewObjectName = BackendTemplateView::class; - protected ApplicationRepository $applicationRepository; - - public function __construct(ApplicationRepository $applicationRepository) - { + protected ModuleTemplateFactory $moduleTemplateFactory; + protected IconFactory $iconFactory; + protected BackendUriBuilder $backendUriBuilder; + + public function __construct( + ApplicationRepository $applicationRepository, + ModuleTemplateFactory $moduleTemplateFactory, + IconFactory $iconFactory, + UriBuilder $uriBuilder, + BackendUriBuilder $backendUriBuilder + ) { $this->applicationRepository = $applicationRepository; + $this->moduleTemplateFactory = $moduleTemplateFactory; + $this->iconFactory = $iconFactory; + $this->uriBuilder = $uriBuilder; + $this->backendUriBuilder = $backendUriBuilder; } - public function listAction(): void + public function listAction(): ResponseInterface { + $moduleTemplate = $this->moduleTemplateFactory->create($this->request); // Just an empty view + $moduleTemplate->setContent($this->view->render()); + return $this->htmlResponse($moduleTemplate->renderContent()); } - public function initializeView(ViewInterface $view): void + public function initView(): ModuleTemplate { - parent::initializeView($view); + $moduleTemplate = $this->moduleTemplateFactory->create($this->request); + $this->createMenu($moduleTemplate); + $this->createButtonBar($moduleTemplate); - if ($this->request->getControllerName() !== 'Backend' && $view instanceof BackendTemplateView) { - $view->getModuleTemplate()->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/Modal'); - $this->createMenu(); - $this->createButtonBar(); - } + return $moduleTemplate; } - protected function createMenu(): void + protected function createMenu(ModuleTemplate $moduleTemplate): void { - $menu = $this->view->getModuleTemplate()->getDocHeaderComponent()->getMenuRegistry()->makeMenu(); + $menu = $moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu(); $menu->setIdentifier('auth0'); $actions = [ @@ -92,28 +100,28 @@ protected function createMenu(): void ); } - $this->view->getModuleTemplate()->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu); + $moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu); } - protected function createButtonBar(): void + protected function createButtonBar(ModuleTemplate $moduleTemplate): void { - $buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar(); + $buttonBar = $moduleTemplate->getDocHeaderComponent()->getButtonBar(); $listButton = $buttonBar->makeLinkButton() ->setTitle($this->getTranslation('menu.button.overview')) ->setHref($this->getUriBuilder()->reset()->uriFor('list', [], 'Backend')) - ->setIcon($this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-viewmode-tiles', Icon::SIZE_SMALL)); - $buttonBar->addButton($listButton, ButtonBar::BUTTON_POSITION_LEFT); + ->setIcon($this->iconFactory->getIcon('actions-viewmode-tiles', Icon::SIZE_SMALL)); + $buttonBar->addButton($listButton); } - protected function addButton(string $label, string $actionName, string $controllerName, string $icon): void + protected function addButton(string $label, string $actionName, string $controllerName, string $icon, ModuleTemplate $moduleTemplate): void { - $buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar(); + $buttonBar = $moduleTemplate->getDocHeaderComponent()->getButtonBar(); $linkButton = $buttonBar->makeLinkButton() ->setTitle($this->getTranslation($label)) ->setHref($this->getUriBuilder()->reset()->uriFor($actionName, [], $controllerName)) - ->setIcon($this->view->getModuleTemplate()->getIconFactory()->getIcon($icon, Icon::SIZE_SMALL)); + ->setIcon($this->iconFactory->getIcon($icon, Icon::SIZE_SMALL)); $buttonBar->addButton($linkButton, ButtonBar::BUTTON_POSITION_RIGHT); } @@ -123,8 +131,6 @@ protected function addButton(string $label, string $actionName, string $controll */ protected function getModuleUrl(bool $encoded = true, string $referenceType = BackendUriBuilder::ABSOLUTE_PATH): string { - $backendUriBuilder = $this->objectManager->get(BackendUriBuilder::class); - $parameters = [ 'tx_auth0_tools_auth0auth0' => [ 'action' => $this->request->getControllerActionName(), @@ -132,17 +138,16 @@ protected function getModuleUrl(bool $encoded = true, string $referenceType = Ba ], ]; - $uri = $backendUriBuilder->buildUriFromRoute('tools_Auth0Auth0', $parameters, $referenceType); + $uri = $this->backendUriBuilder->buildUriFromRoute('tools_Auth0Auth0', $parameters, $referenceType); return $encoded ? rawurlencode($uri) : $uri; } protected function getUriBuilder(): UriBuilder { - $uriBuilder = $this->objectManager->get(UriBuilder::class); - $uriBuilder->setRequest($this->request); + $this->uriBuilder->setRequest($this->request); - return $uriBuilder; + return $this->uriBuilder; } protected function getTranslation($key): string diff --git a/Classes/Controller/LoginController.php b/Classes/Controller/LoginController.php index c03de4a4..69c2c4f9 100644 --- a/Classes/Controller/LoginController.php +++ b/Classes/Controller/LoginController.php @@ -11,17 +11,18 @@ * Florian Wessels , Leuchtfeuer Digital Marketing */ -namespace Bitmotion\Auth0\Controller; +namespace Leuchtfeuer\Auth0\Controller; use Auth0\SDK\Auth0; use Auth0\SDK\Exception\ConfigurationException; -use Bitmotion\Auth0\Domain\Repository\ApplicationRepository; -use Bitmotion\Auth0\Domain\Transfer\EmAuth0Configuration; -use Bitmotion\Auth0\Factory\ApplicationFactory; -use Bitmotion\Auth0\Middleware\CallbackMiddleware; -use Bitmotion\Auth0\Utility\ParametersUtility; -use Bitmotion\Auth0\Utility\RoutingUtility; -use Bitmotion\Auth0\Utility\TokenUtility; +use Leuchtfeuer\Auth0\Domain\Repository\ApplicationRepository; +use Leuchtfeuer\Auth0\Domain\Transfer\EmAuth0Configuration; +use Leuchtfeuer\Auth0\Factory\ApplicationFactory; +use Leuchtfeuer\Auth0\Middleware\CallbackMiddleware; +use Leuchtfeuer\Auth0\Utility\ParametersUtility; +use Leuchtfeuer\Auth0\Utility\RoutingUtility; +use Leuchtfeuer\Auth0\Utility\TokenUtility; +use Psr\Http\Message\ResponseInterface; use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerAwareTrait; use TYPO3\CMS\Core\Context\Context; @@ -62,7 +63,7 @@ public function initializeAction(): void /** * @throws AspectNotFoundException */ - public function formAction(): void + public function formAction(): ResponseInterface { if (GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('frontend.user', 'isLoggedIn')) { // Get Auth0 user from session storage @@ -75,6 +76,7 @@ public function formAction(): void 'auth0Error' => $this->error, 'auth0ErrorDescription' => $this->errorDescription, ]); + return $this->htmlResponse(); } /** diff --git a/Classes/Controller/PropertyController.php b/Classes/Controller/PropertyController.php index 48845f0f..5c80d3e4 100644 --- a/Classes/Controller/PropertyController.php +++ b/Classes/Controller/PropertyController.php @@ -9,46 +9,55 @@ * Florian Wessels , Leuchtfeuer Digital Marketing */ -namespace Bitmotion\Auth0\Controller; +namespace Leuchtfeuer\Auth0\Controller; -use Bitmotion\Auth0\Configuration\Auth0Configuration; -use Bitmotion\Auth0\Domain\Transfer\EmAuth0Configuration; -use Bitmotion\Auth0\Factory\ConfigurationFactory; -use Bitmotion\Auth0\Utility\TcaUtility; +use Leuchtfeuer\Auth0\Configuration\Auth0Configuration; +use Leuchtfeuer\Auth0\Domain\Transfer\EmAuth0Configuration; +use Leuchtfeuer\Auth0\Factory\ConfigurationFactory; +use Leuchtfeuer\Auth0\Utility\TcaUtility; +use Psr\Http\Message\ResponseInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Extbase\Http\ForwardResponse; use TYPO3\CMS\Extbase\Mvc\Exception\StopActionException; class PropertyController extends BackendController { - public function listAction(): void + public function listAction(): ResponseInterface { $tcaUtility = new TcaUtility(); - + $moduleTemplate = $this->initView(); $this->view->assignMultiple([ 'frontendUserColumns' => $tcaUtility->getColumnsFromTable('fe_users'), 'backendUserColumns' => $tcaUtility->getColumnsFromTable('be_users'), 'extensionConfiguration' => new EmAuth0Configuration(), 'yamlConfiguration' => GeneralUtility::makeInstance(Auth0Configuration::class)->load(), ]); + $moduleTemplate->setContent($this->view->render()); + + return $this->htmlResponse($moduleTemplate->renderContent()); } - public function newAction(string $table, string $type): void + public function newAction(string $table, string $type): ResponseInterface { - $this->addButton('menu.button.cancel', 'list', 'Property', 'actions-close'); + $moduleTemplate = $this->initView(); + $this->addButton('menu.button.cancel', 'list', 'Property', 'actions-close', $moduleTemplate); $this->view->assignMultiple([ 'table' => $table, 'type' => $type, 'properties' => (new TcaUtility())->getUnusedColumnsFromTable($table), ]); + $moduleTemplate->setContent($this->view->render()); + + return $this->htmlResponse($moduleTemplate->renderContent()); } /** * @throws StopActionException */ - public function createAction(array $property, string $table, string $type): void + public function createAction(array $property, string $table, string $type): ResponseInterface { if (empty($property['databaseField']) || empty($property['auth0Property'])) { - $this->forward('new'); + return new ForwardResponse('new'); } ksort($property); @@ -57,15 +66,15 @@ public function createAction(array $property, string $table, string $type): void $configuration = $auth0Configuration->load(); $configuration['properties'][$table][$type][] = $propertyConfiguration; $auth0Configuration->write($configuration); - $this->addFlashMessage($this->getTranslation('message.property.created.text'), $this->getTranslation('message.property.created.title')); - $this->redirect('list'); + + return $this->redirect('list'); } /** * @throws StopActionException */ - public function deleteAction(array $property, string $table, string $type): void + public function deleteAction(array $property, string $table, string $type): ResponseInterface { if ((bool)$property['readOnly'] === false) { $auth0Configuration = GeneralUtility::makeInstance(Auth0Configuration::class); @@ -82,24 +91,29 @@ public function deleteAction(array $property, string $table, string $type): void } $this->addFlashMessage($this->getTranslation('message.property.deleted.text'), $this->getTranslation('message.property.deleted.title')); - $this->redirect('list'); + + return $this->redirect('list'); } - public function editAction(array $property, string $table, string $type): void + public function editAction(array $property, string $table, string $type): ResponseInterface { - $this->addButton('menu.button.cancel', 'list', 'Property', 'actions-close'); + $moduleTemplate = $this->initView(); + $this->addButton('menu.button.cancel', 'list', 'Property', 'actions-close', $moduleTemplate); $this->view->assignMultiple([ 'property' => $property, 'table' => $table, 'type' => $type, 'properties' => (new TcaUtility())->getUnusedColumnsFromTable($table, $property['databaseField']), ]); + $moduleTemplate->setContent($this->view->render()); + + return $this->htmlResponse($moduleTemplate->renderContent()); } /** * @throws StopActionException */ - public function updateAction(array $property, string $table, string $type): void + public function updateAction(array $property, string $table, string $type): ResponseInterface { $auth0Configuration = GeneralUtility::makeInstance(Auth0Configuration::class); $configuration = $auth0Configuration->load(); @@ -113,6 +127,7 @@ public function updateAction(array $property, string $table, string $type): void $auth0Configuration->write($configuration); $this->addFlashMessage($this->getTranslation('message.property.updated.text'), $this->getTranslation('message.property.updated.title')); - $this->redirect('list'); + + return $this->redirect('list'); } } diff --git a/Classes/Controller/RoleController.php b/Classes/Controller/RoleController.php index 909ccc6b..60874fcd 100644 --- a/Classes/Controller/RoleController.php +++ b/Classes/Controller/RoleController.php @@ -9,26 +9,30 @@ * Florian Wessels , Leuchtfeuer Digital Marketing */ -namespace Bitmotion\Auth0\Controller; +namespace Leuchtfeuer\Auth0\Controller; -use Bitmotion\Auth0\Configuration\Auth0Configuration; -use Bitmotion\Auth0\Domain\Repository\UserGroup\BackendUserGroupRepository; -use Bitmotion\Auth0\Domain\Repository\UserGroup\FrontendUserGroupRepository; -use Bitmotion\Auth0\Domain\Transfer\EmAuth0Configuration; -use Bitmotion\Auth0\Factory\ConfigurationFactory; +use Leuchtfeuer\Auth0\Configuration\Auth0Configuration; +use Leuchtfeuer\Auth0\Domain\Repository\UserGroup\BackendUserGroupRepository; +use Leuchtfeuer\Auth0\Domain\Repository\UserGroup\FrontendUserGroupRepository; +use Leuchtfeuer\Auth0\Domain\Transfer\EmAuth0Configuration; +use Leuchtfeuer\Auth0\Factory\ConfigurationFactory; use Psr\Http\Message\ResponseInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; class RoleController extends BackendController { - public function listAction(): void + public function listAction(): ResponseInterface { + $moduleTemplate = $this->initView(); $this->view->assignMultiple([ 'frontendUserGroupMapping' => (new FrontendUserGroupRepository())->findAll(), 'backendUserGroupMapping' => (new BackendUserGroupRepository())->findAll(), 'extensionConfiguration' => new EmAuth0Configuration(), 'yamlConfiguration' => GeneralUtility::makeInstance(Auth0Configuration::class)->load(), ]); + $moduleTemplate->setContent($this->view->render()); + + return $this->htmlResponse($moduleTemplate->renderContent()); } /** @@ -57,6 +61,7 @@ public function updateAction( $auth0Configuration->write($configuration); $this->addFlashMessage($this->getTranslation('message.role.updated.text'), $this->getTranslation('message.role.updated.title')); + return $this->redirect('list'); } } diff --git a/Classes/Domain/Model/Application.php b/Classes/Domain/Model/Application.php index f54e76c5..a28304e7 100644 --- a/Classes/Domain/Model/Application.php +++ b/Classes/Domain/Model/Application.php @@ -11,7 +11,7 @@ * Florian Wessels , Leuchtfeuer Digital Marketing */ -namespace Bitmotion\Auth0\Domain\Model; +namespace Leuchtfeuer\Auth0\Domain\Model; use TYPO3\CMS\Extbase\DomainObject\AbstractEntity; @@ -61,9 +61,11 @@ public function getTitle(): string return $this->title; } - public function setTitle(string $title): void + public function setTitle(string $title): self { $this->title = $title; + + return $this; } public function getClientId(): string @@ -71,9 +73,11 @@ public function getClientId(): string return $this->id; } - public function setId(string $id): void + public function setId(string $id): self { $this->id = $id; + + return $this; } public function getClientSecret(): string @@ -81,9 +85,11 @@ public function getClientSecret(): string return $this->secret; } - public function setSecret(string $secret): void + public function setSecret(string $secret): self { $this->secret = $secret; + + return $this; } public function getDomain(): string @@ -91,9 +97,11 @@ public function getDomain(): string return $this->domain; } - public function setDomain(string $domain): void + public function setDomain(string $domain): self { $this->domain = $domain; + + return $this; } public function getFullDomain(): string @@ -115,9 +123,11 @@ public function getAudience(bool $asFullDomain = false): string return $this->audience; } - public function setAudience(string $audience): void + public function setAudience(string $audience): self { $this->audience = trim($audience, '/') . '/'; + + return $this; } public function getApiBasePath(): string @@ -130,9 +140,11 @@ public function isSingleLogOut(): bool return $this->singleLogOut; } - public function setSingleLogOut(bool $singleLogOut): void + public function setSingleLogOut(bool $singleLogOut): self { $this->singleLogOut = $singleLogOut; + + return $this; } public function getSignatureAlgorithm(): string @@ -140,9 +152,11 @@ public function getSignatureAlgorithm(): string return $this->signatureAlgorithm; } - public function setSignatureAlgorithm(string $signatureAlgorithm): void + public function setSignatureAlgorithm(string $signatureAlgorithm): self { $this->signatureAlgorithm = $signatureAlgorithm; + + return $this; } public function isCustomDomain(): bool @@ -155,8 +169,23 @@ public function hasApi(): bool return $this->api; } - public function setApi(bool $api): void + public function setApi(bool $api): self { $this->api = $api; + + return $this; + } + + public static function fromArray(array $data): self + { + return (new self()) + ->setTitle($data['title']) + ->setId($data['id']) + ->setSecret($data['secret']) + ->setDomain($data['domain']) + ->setAudience($data['audience']) + ->setSingleLogOut((bool)$data['single_log_out']) + ->setSignatureAlgorithm($data['signature_algorithm'] ?? '') + ->setApi((bool)$data['api']); } } diff --git a/Classes/Domain/Repository/ApplicationRepository.php b/Classes/Domain/Repository/ApplicationRepository.php index 02162543..755e9cba 100644 --- a/Classes/Domain/Repository/ApplicationRepository.php +++ b/Classes/Domain/Repository/ApplicationRepository.php @@ -11,12 +11,11 @@ * Florian Wessels , Leuchtfeuer Digital Marketing */ -namespace Bitmotion\Auth0\Domain\Repository; +namespace Leuchtfeuer\Auth0\Domain\Repository; -use Bitmotion\Auth0\Domain\Model\Application; +use Leuchtfeuer\Auth0\Domain\Model\Application; use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager; class ApplicationRepository { @@ -24,7 +23,22 @@ class ApplicationRepository public function findByUid(int $uid): ?Application { - return GeneralUtility::makeInstance(PersistenceManager::class)->getObjectByIdentifier($uid, Application::class); + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) + ->getQueryBuilderForTable(self::TABLE_NAME); + $applicationArray = $queryBuilder + ->select('*') + ->from(self::TABLE_NAME) + ->where( + $queryBuilder->expr()->eq('uid', $uid) + ) + ->setMaxResults(1) + ->executeQuery()->fetchAllAssociative() ?? []; + + if (empty($applicationArray)) { + return null; + } + + return Application::fromArray($applicationArray[0]); } public function findAll(): array diff --git a/Classes/Domain/Repository/FrontendUserRepository.php b/Classes/Domain/Repository/FrontendUserRepository.php index c8574873..cbde3469 100644 --- a/Classes/Domain/Repository/FrontendUserRepository.php +++ b/Classes/Domain/Repository/FrontendUserRepository.php @@ -11,7 +11,7 @@ * Florian Wessels , Leuchtfeuer Digital Marketing */ -namespace Bitmotion\Auth0\Domain\Repository; +namespace Leuchtfeuer\Auth0\Domain\Repository; use TYPO3\CMS\Extbase\Persistence\Repository; diff --git a/Classes/Domain/Repository/UserGroup/AbstractUserGroupRepository.php b/Classes/Domain/Repository/UserGroup/AbstractUserGroupRepository.php index 3e4f7e0b..c0a2720d 100644 --- a/Classes/Domain/Repository/UserGroup/AbstractUserGroupRepository.php +++ b/Classes/Domain/Repository/UserGroup/AbstractUserGroupRepository.php @@ -9,7 +9,7 @@ * Florian Wessels , Leuchtfeuer Digital Marketing */ -namespace Bitmotion\Auth0\Domain\Repository\UserGroup; +namespace Leuchtfeuer\Auth0\Domain\Repository\UserGroup; use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Database\Query\QueryBuilder; diff --git a/Classes/Domain/Repository/UserGroup/BackendUserGroupRepository.php b/Classes/Domain/Repository/UserGroup/BackendUserGroupRepository.php index b9092916..1eb5f5a1 100644 --- a/Classes/Domain/Repository/UserGroup/BackendUserGroupRepository.php +++ b/Classes/Domain/Repository/UserGroup/BackendUserGroupRepository.php @@ -9,7 +9,7 @@ * Florian Wessels , Leuchtfeuer Digital Marketing */ -namespace Bitmotion\Auth0\Domain\Repository\UserGroup; +namespace Leuchtfeuer\Auth0\Domain\Repository\UserGroup; class BackendUserGroupRepository extends AbstractUserGroupRepository { diff --git a/Classes/Domain/Repository/UserGroup/FrontendUserGroupRepository.php b/Classes/Domain/Repository/UserGroup/FrontendUserGroupRepository.php index 3a13ec2a..1fa2d92b 100644 --- a/Classes/Domain/Repository/UserGroup/FrontendUserGroupRepository.php +++ b/Classes/Domain/Repository/UserGroup/FrontendUserGroupRepository.php @@ -9,7 +9,7 @@ * Florian Wessels , Leuchtfeuer Digital Marketing */ -namespace Bitmotion\Auth0\Domain\Repository\UserGroup; +namespace Leuchtfeuer\Auth0\Domain\Repository\UserGroup; class FrontendUserGroupRepository extends AbstractUserGroupRepository { diff --git a/Classes/Domain/Repository/UserRepository.php b/Classes/Domain/Repository/UserRepository.php index aafb56e5..c3bb3080 100644 --- a/Classes/Domain/Repository/UserRepository.php +++ b/Classes/Domain/Repository/UserRepository.php @@ -11,9 +11,9 @@ * Florian Wessels , Leuchtfeuer Digital Marketing */ -namespace Bitmotion\Auth0\Domain\Repository; +namespace Leuchtfeuer\Auth0\Domain\Repository; -use Bitmotion\Auth0\Domain\Transfer\EmAuth0Configuration; +use Leuchtfeuer\Auth0\Domain\Transfer\EmAuth0Configuration; use Psr\Http\Message\ServerRequestInterface; use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerAwareTrait; diff --git a/Classes/Domain/Transfer/EmAuth0Configuration.php b/Classes/Domain/Transfer/EmAuth0Configuration.php index 0c071179..d1acf6ce 100644 --- a/Classes/Domain/Transfer/EmAuth0Configuration.php +++ b/Classes/Domain/Transfer/EmAuth0Configuration.php @@ -11,9 +11,9 @@ * Florian Wessels , Leuchtfeuer Digital Marketing */ -namespace Bitmotion\Auth0\Domain\Transfer; +namespace Leuchtfeuer\Auth0\Domain\Transfer; -use Bitmotion\Auth0\Utility\ParametersUtility; +use Leuchtfeuer\Auth0\Utility\ParametersUtility; use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationExtensionNotConfiguredException; use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationPathDoesNotExistException; use TYPO3\CMS\Core\Configuration\ExtensionConfiguration; diff --git a/Classes/ErrorCode.php b/Classes/ErrorCode.php index 3c70b105..5bbb7d47 100644 --- a/Classes/ErrorCode.php +++ b/Classes/ErrorCode.php @@ -11,7 +11,7 @@ * Florian Wessels , Leuchtfeuer Digital Marketing */ -namespace Bitmotion\Auth0; +namespace Leuchtfeuer\Auth0; final class ErrorCode { diff --git a/Classes/Event/RedirectPreProcessingEvent.php b/Classes/Event/RedirectPreProcessingEvent.php index 1d0709af..8127b7e4 100644 --- a/Classes/Event/RedirectPreProcessingEvent.php +++ b/Classes/Event/RedirectPreProcessingEvent.php @@ -11,9 +11,9 @@ * Florian Wessels , Leuchtfeuer Digital Marketing */ -namespace Bitmotion\Auth0\Event; +namespace Leuchtfeuer\Auth0\Event; -use Bitmotion\Auth0\Service\RedirectService; +use Leuchtfeuer\Auth0\Service\RedirectService; final class RedirectPreProcessingEvent { diff --git a/Classes/EventListener/AfterPackageActivation.php b/Classes/EventListener/AfterPackageActivation.php index 4eb6d107..ac233095 100644 --- a/Classes/EventListener/AfterPackageActivation.php +++ b/Classes/EventListener/AfterPackageActivation.php @@ -11,7 +11,7 @@ * Florian Wessels , Leuchtfeuer Digital Marketing */ -namespace Bitmotion\Auth0\EventListener; +namespace Leuchtfeuer\Auth0\EventListener; use TYPO3\CMS\Core\Configuration\ConfigurationManager; use TYPO3\CMS\Core\Package\Event\AfterPackageActivationEvent; diff --git a/Classes/Exception/TokenException.php b/Classes/Exception/TokenException.php index 4aea981a..8c4e85b3 100644 --- a/Classes/Exception/TokenException.php +++ b/Classes/Exception/TokenException.php @@ -11,7 +11,7 @@ * Florian Wessels , Leuchtfeuer Digital Marketing */ -namespace Bitmotion\Auth0\Exception; +namespace Leuchtfeuer\Auth0\Exception; class TokenException extends \Exception { diff --git a/Classes/Exception/UnknownErrorCodeException.php b/Classes/Exception/UnknownErrorCodeException.php index 8f8b27aa..08f3edd0 100644 --- a/Classes/Exception/UnknownErrorCodeException.php +++ b/Classes/Exception/UnknownErrorCodeException.php @@ -11,7 +11,7 @@ * Florian Wessels , Leuchtfeuer Digital Marketing */ -namespace Bitmotion\Auth0\Exception; +namespace Leuchtfeuer\Auth0\Exception; class UnknownErrorCodeException extends \Exception { diff --git a/Classes/Factory/ApplicationFactory.php b/Classes/Factory/ApplicationFactory.php index 85826e05..f707bdc5 100644 --- a/Classes/Factory/ApplicationFactory.php +++ b/Classes/Factory/ApplicationFactory.php @@ -9,16 +9,16 @@ * Florian Wessels , Leuchtfeuer Digital Marketing */ -namespace Bitmotion\Auth0\Factory; +namespace Leuchtfeuer\Auth0\Factory; use Auth0\SDK\Auth0; use Auth0\SDK\Configuration\SdkConfiguration; use Auth0\SDK\Exception\ConfigurationException; -use Bitmotion\Auth0\Domain\Model\Application; -use Bitmotion\Auth0\Domain\Repository\ApplicationRepository; -use Bitmotion\Auth0\Middleware\CallbackMiddleware; use GuzzleHttp\Client; use GuzzleHttp\Exception\GuzzleException; +use Leuchtfeuer\Auth0\Domain\Model\Application; +use Leuchtfeuer\Auth0\Domain\Repository\ApplicationRepository; +use Leuchtfeuer\Auth0\Middleware\CallbackMiddleware; use TYPO3\CMS\Core\Utility\GeneralUtility; class ApplicationFactory diff --git a/Classes/Factory/ConfigurationFactory.php b/Classes/Factory/ConfigurationFactory.php index 887bcdc8..314adcac 100644 --- a/Classes/Factory/ConfigurationFactory.php +++ b/Classes/Factory/ConfigurationFactory.php @@ -9,7 +9,7 @@ * Florian Wessels , Leuchtfeuer Digital Marketing */ -namespace Bitmotion\Auth0\Factory; +namespace Leuchtfeuer\Auth0\Factory; class ConfigurationFactory { diff --git a/Classes/Hooks/PageLayoutViewHook.php b/Classes/Hooks/PageLayoutViewHook.php index d9cd5de5..3e9c1021 100644 --- a/Classes/Hooks/PageLayoutViewHook.php +++ b/Classes/Hooks/PageLayoutViewHook.php @@ -11,7 +11,7 @@ * Florian Wessels , Leuchtfeuer Digital Marketing */ -namespace Bitmotion\Auth0\Hooks; +namespace Leuchtfeuer\Auth0\Hooks; use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Localization\LanguageService; diff --git a/Classes/Hooks/SingleSignOutHook.php b/Classes/Hooks/SingleSignOutHook.php index bc9b4223..1a59e473 100644 --- a/Classes/Hooks/SingleSignOutHook.php +++ b/Classes/Hooks/SingleSignOutHook.php @@ -11,9 +11,9 @@ * Florian Wessels , Leuchtfeuer Digital Marketing */ -namespace Bitmotion\Auth0\Hooks; +namespace Leuchtfeuer\Auth0\Hooks; -use Bitmotion\Auth0\Domain\Transfer\EmAuth0Configuration; +use Leuchtfeuer\Auth0\Domain\Transfer\EmAuth0Configuration; use Psr\Http\Message\ServerRequestInterface; use TYPO3\CMS\Core\Http\ApplicationType; use TYPO3\CMS\Core\SingletonInterface; diff --git a/Classes/LoginProvider/Auth0Provider.php b/Classes/LoginProvider/Auth0Provider.php index 24424be3..bf904ef1 100644 --- a/Classes/LoginProvider/Auth0Provider.php +++ b/Classes/LoginProvider/Auth0Provider.php @@ -11,22 +11,22 @@ * Florian Wessels , Leuchtfeuer Digital Marketing */ -namespace Bitmotion\Auth0\LoginProvider; +namespace Leuchtfeuer\Auth0\LoginProvider; use Auth0\SDK\Auth0; use Auth0\SDK\Exception\ConfigurationException; -use Bitmotion\Auth0\Domain\Model\Application; -use Bitmotion\Auth0\Domain\Repository\ApplicationRepository; -use Bitmotion\Auth0\Domain\Transfer\EmAuth0Configuration; -use Bitmotion\Auth0\Factory\ApplicationFactory; -use Bitmotion\Auth0\Middleware\CallbackMiddleware; -use Bitmotion\Auth0\Utility\TokenUtility; use GuzzleHttp\Exception\GuzzleException; +use Leuchtfeuer\Auth0\Domain\Model\Application; +use Leuchtfeuer\Auth0\Domain\Repository\ApplicationRepository; +use Leuchtfeuer\Auth0\Domain\Transfer\EmAuth0Configuration; +use Leuchtfeuer\Auth0\Factory\ApplicationFactory; +use Leuchtfeuer\Auth0\Middleware\CallbackMiddleware; +use Leuchtfeuer\Auth0\Utility\ModeUtility; +use Leuchtfeuer\Auth0\Utility\TokenUtility; use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerAwareTrait; use TYPO3\CMS\Backend\Controller\LoginController; use TYPO3\CMS\Backend\LoginProvider\LoginProviderInterface; -use TYPO3\CMS\Core\Information\Typo3Version; use TYPO3\CMS\Core\Page\PageRenderer; use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -123,6 +123,7 @@ protected function setAuth0(): bool protected function getCallback(?string $redirectUri = ''): string { $tokenUtility = new TokenUtility(); + $tokenUtility->withPayload('environment', ModeUtility::BACKEND_MODE); $tokenUtility->withPayload('application', $this->configuration->getBackendConnection()); if ($redirectUri !== '') { @@ -180,8 +181,7 @@ protected function isTypoScriptLoaded(): bool protected function prepareView(StandaloneView &$standaloneView, PageRenderer &$pageRenderer): void { - $templateName = version_compare(GeneralUtility::makeInstance(Typo3Version::class)->getVersion(), '11.0', '>=') ? 'BackendV11' : 'Backend'; - $standaloneView->setTemplate($templateName); + $standaloneView->setTemplate($this->getTemplateName()); $standaloneView->setLayoutRootPaths($this->frameworkConfiguration['view']['layoutRootPaths']); $standaloneView->setTemplateRootPaths($this->frameworkConfiguration['view']['templateRootPaths']); @@ -191,9 +191,8 @@ protected function prepareView(StandaloneView &$standaloneView, PageRenderer &$p protected function getDefaultView(StandaloneView &$standaloneView, PageRenderer &$pageRenderer): void { $standaloneView->setLayoutRootPaths(['EXT:auth0/Resources/Private/Layouts/']); - $templateName = version_compare(GeneralUtility::makeInstance(Typo3Version::class)->getVersion(), '11.0', '>=') ? 'BackendV11' : 'Backend'; $standaloneView->setTemplatePathAndFilename( - GeneralUtility::getFileAbsFileName('EXT:auth0/Resources/Private/Templates/' . $templateName . '.html') + GeneralUtility::getFileAbsFileName('EXT:auth0/Resources/Private/Templates/' . $this->getTemplateName() . '.html') ); $standaloneView->assign('error', 'no_typoscript'); $pageRenderer->addCssFile('EXT:auth0/Resources/Public/Styles/backend.css'); @@ -213,4 +212,11 @@ protected function logoutFromAuth0(): void } exit(); } + + private function getTemplateName(): string + { + $templateName = ModeUtility::isTYPO3V12() ? 'BackendV12' : 'BackendV11'; + + return 'LoginProvider/' . $templateName; + } } diff --git a/Classes/Middleware/CallbackMiddleware.php b/Classes/Middleware/CallbackMiddleware.php index 561fba09..8fa543ab 100644 --- a/Classes/Middleware/CallbackMiddleware.php +++ b/Classes/Middleware/CallbackMiddleware.php @@ -11,23 +11,25 @@ * Florian Wessels , Leuchtfeuer Digital Marketing */ -namespace Bitmotion\Auth0\Middleware; +namespace Leuchtfeuer\Auth0\Middleware; use Auth0\SDK\Exception\ArgumentException; +use Auth0\SDK\Exception\ConfigurationException; use Auth0\SDK\Exception\NetworkException; use Auth0\SDK\Utility\HttpResponse; -use Bitmotion\Auth0\Domain\Repository\ApplicationRepository; -use Bitmotion\Auth0\Domain\Transfer\EmAuth0Configuration; -use Bitmotion\Auth0\ErrorCode; -use Bitmotion\Auth0\Exception\TokenException; -use Bitmotion\Auth0\Exception\UnknownErrorCodeException; -use Bitmotion\Auth0\Factory\ApplicationFactory; -use Bitmotion\Auth0\LoginProvider\Auth0Provider; -use Bitmotion\Auth0\Service\RedirectService; -use Bitmotion\Auth0\Utility\Database\UpdateUtility; -use Bitmotion\Auth0\Utility\TokenUtility; -use Bitmotion\Auth0\Utility\UserUtility; +use GuzzleHttp\Exception\GuzzleException; use Lcobucci\JWT\Token\DataSet; +use Leuchtfeuer\Auth0\Domain\Repository\ApplicationRepository; +use Leuchtfeuer\Auth0\Domain\Transfer\EmAuth0Configuration; +use Leuchtfeuer\Auth0\ErrorCode; +use Leuchtfeuer\Auth0\Exception\TokenException; +use Leuchtfeuer\Auth0\Exception\UnknownErrorCodeException; +use Leuchtfeuer\Auth0\Factory\ApplicationFactory; +use Leuchtfeuer\Auth0\LoginProvider\Auth0Provider; +use Leuchtfeuer\Auth0\Service\RedirectService; +use Leuchtfeuer\Auth0\Utility\Database\UpdateUtility; +use Leuchtfeuer\Auth0\Utility\TokenUtility; +use Leuchtfeuer\Auth0\Utility\UserUtility; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; @@ -183,8 +185,8 @@ protected function isUserLoggedIn(ServerRequestInterface $request): bool /** * @throws ArgumentException * @throws NetworkException - * @throws \Auth0\SDK\Exception\ConfigurationException - * @throws \GuzzleHttp\Exception\GuzzleException + * @throws ConfigurationException + * @throws GuzzleException */ protected function updateTypo3User(int $applicationId, array $user): void { diff --git a/Classes/Service/AuthenticationService.php b/Classes/Service/AuthenticationService.php index 44bfa835..5122e9f2 100644 --- a/Classes/Service/AuthenticationService.php +++ b/Classes/Service/AuthenticationService.php @@ -11,24 +11,24 @@ * Florian Wessels , Leuchtfeuer Digital Marketing */ -namespace Bitmotion\Auth0\Service; +namespace Leuchtfeuer\Auth0\Service; use Auth0\SDK\Auth0; use Auth0\SDK\Exception\ArgumentException; use Auth0\SDK\Exception\NetworkException; use Auth0\SDK\Utility\HttpResponse; -use Bitmotion\Auth0\Domain\Transfer\EmAuth0Configuration; -use Bitmotion\Auth0\ErrorCode; -use Bitmotion\Auth0\Exception\TokenException; -use Bitmotion\Auth0\Factory\ApplicationFactory; -use Bitmotion\Auth0\LoginProvider\Auth0Provider; -use Bitmotion\Auth0\Middleware\CallbackMiddleware; -use Bitmotion\Auth0\Utility\Database\UpdateUtility; -use Bitmotion\Auth0\Utility\TokenUtility; -use Bitmotion\Auth0\Utility\UserUtility; use GuzzleHttp\Exception\GuzzleException; use JsonException; +use Leuchtfeuer\Auth0\Domain\Transfer\EmAuth0Configuration; +use Leuchtfeuer\Auth0\ErrorCode; +use Leuchtfeuer\Auth0\Exception\TokenException; +use Leuchtfeuer\Auth0\Factory\ApplicationFactory; +use Leuchtfeuer\Auth0\LoginProvider\Auth0Provider; +use Leuchtfeuer\Auth0\Middleware\CallbackMiddleware; +use Leuchtfeuer\Auth0\Utility\Database\UpdateUtility; +use Leuchtfeuer\Auth0\Utility\TokenUtility; +use Leuchtfeuer\Auth0\Utility\UserUtility; use TYPO3\CMS\Core\Authentication\AuthenticationService as BasicAuthenticationService; use TYPO3\CMS\Core\Authentication\LoginType; use TYPO3\CMS\Core\Crypto\PasswordHashing\InvalidPasswordHashException; @@ -186,8 +186,8 @@ protected function initSessionStore(string $loginType): bool { echo 'do not hit'; die(); -// $session = (new SessionFactory())->getSessionStoreForApplication(0, $loginType); -// $userInfo = $session->getUserInfo(); + // $session = (new SessionFactory())->getSessionStoreForApplication(0, $loginType); + // $userInfo = $session->getUserInfo(); // TODO: Check if context needs to be set $userInfo = $this->auth0->configuration()->getSessionStorage()->get('user'); @@ -357,13 +357,13 @@ public function authUser(array $user): int return 100; } -// // Do not login if email address is not verified (only available if API is enabled) -// // TODO:: Support this even API is disabled -// if ($this->auth0User !== null && !$this->auth0User->isEmailVerified()) { -// $this->logger->warning('Email not verified. Do not login user.'); -// // Responsible, authentication failed, do NOT check other services -// return 0; -// } + // // Do not login if email address is not verified (only available if API is enabled) + // // TODO:: Support this even API is disabled + // if ($this->auth0User !== null && !$this->auth0User->isEmailVerified()) { + // $this->logger->warning('Email not verified. Do not login user.'); + // // Responsible, authentication failed, do NOT check other services + // return 0; + // } // Skip when there is an Auth0 session but the corresponding TYPO3 user has no user group assigned. if (empty($user['usergroup']) && $this->loginViaSession === true) { diff --git a/Classes/Service/RedirectService.php b/Classes/Service/RedirectService.php index e10dcb37..5223adb6 100644 --- a/Classes/Service/RedirectService.php +++ b/Classes/Service/RedirectService.php @@ -11,9 +11,9 @@ * Florian Wessels , Leuchtfeuer Digital Marketing */ -namespace Bitmotion\Auth0\Service; +namespace Leuchtfeuer\Auth0\Service; -use Bitmotion\Auth0\Event\RedirectPreProcessingEvent; +use Leuchtfeuer\Auth0\Event\RedirectPreProcessingEvent; use Psr\EventDispatcher\EventDispatcherInterface; use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerAwareTrait; @@ -24,7 +24,6 @@ use TYPO3\CMS\Core\Log\LogManager; use TYPO3\CMS\Core\Site\SiteFinder; use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Core\Utility\StringUtility; use TYPO3\CMS\Felogin\Controller\FrontendLoginController; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; @@ -267,10 +266,7 @@ protected function isRelativeUrl($url) $parsedUrl = @parse_url($url); if ($parsedUrl !== false && !isset($parsedUrl['scheme']) && !isset($parsedUrl['host'])) { // If the relative URL starts with a slash, we need to check if it's within the current site path - return $parsedUrl['path'][0] !== '/' || GeneralUtility::isFirstPartOfStr( - $parsedUrl['path'], - GeneralUtility::getIndpEnv('TYPO3_SITE_PATH') - ); + return $parsedUrl['path'][0] !== '/' || \str_starts_with($parsedUrl['path'], GeneralUtility::getIndpEnv('TYPO3_SITE_PATH')); } return false; @@ -288,8 +284,8 @@ protected function isInCurrentDomain($url) $urlWithoutSchema = preg_replace('#^https?://#', '', $url); $siteUrlWithoutSchema = preg_replace('#^https?://#', '', GeneralUtility::getIndpEnv('TYPO3_SITE_URL')); - return StringUtility::beginsWith($urlWithoutSchema . '/', GeneralUtility::getIndpEnv('HTTP_HOST') . '/') - && StringUtility::beginsWith($urlWithoutSchema, $siteUrlWithoutSchema); + return \str_starts_with($urlWithoutSchema . '/', GeneralUtility::getIndpEnv('HTTP_HOST') . '/') + && \str_starts_with($urlWithoutSchema, $siteUrlWithoutSchema); } /** @@ -319,7 +315,7 @@ protected function isInLocalDomain(string $url): bool foreach ($localDomains as $localDomain) { // strip trailing slashes (if given) $domainName = rtrim($localDomain['domainName'], '/'); - if (GeneralUtility::isFirstPartOfStr($host . $path . '/', $domainName . '/')) { + if (\str_starts_with($host . $path . '/', $domainName . '/')) { return true; } } diff --git a/Classes/Utility/Database/UpdateUtility.php b/Classes/Utility/Database/UpdateUtility.php index 0f6aaae5..4afb8f45 100644 --- a/Classes/Utility/Database/UpdateUtility.php +++ b/Classes/Utility/Database/UpdateUtility.php @@ -11,15 +11,15 @@ * Florian Wessels , Leuchtfeuer Digital Marketing */ -namespace Bitmotion\Auth0\Utility\Database; - -use Bitmotion\Auth0\Configuration\Auth0Configuration; -use Bitmotion\Auth0\Domain\Repository\UserGroup\AbstractUserGroupRepository; -use Bitmotion\Auth0\Domain\Repository\UserGroup\BackendUserGroupRepository; -use Bitmotion\Auth0\Domain\Repository\UserGroup\FrontendUserGroupRepository; -use Bitmotion\Auth0\Domain\Repository\UserRepository; -use Bitmotion\Auth0\Domain\Transfer\EmAuth0Configuration; -use Bitmotion\Auth0\Utility\ParseFuncUtility; +namespace Leuchtfeuer\Auth0\Utility\Database; + +use Leuchtfeuer\Auth0\Configuration\Auth0Configuration; +use Leuchtfeuer\Auth0\Domain\Repository\UserGroup\AbstractUserGroupRepository; +use Leuchtfeuer\Auth0\Domain\Repository\UserGroup\BackendUserGroupRepository; +use Leuchtfeuer\Auth0\Domain\Repository\UserGroup\FrontendUserGroupRepository; +use Leuchtfeuer\Auth0\Domain\Repository\UserRepository; +use Leuchtfeuer\Auth0\Domain\Transfer\EmAuth0Configuration; +use Leuchtfeuer\Auth0\Utility\ParseFuncUtility; use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerAwareTrait; use TYPO3\CMS\Backend\Utility\BackendUtility; diff --git a/Classes/Utility/ModeUtility.php b/Classes/Utility/ModeUtility.php new file mode 100644 index 00000000..50599808 --- /dev/null +++ b/Classes/Utility/ModeUtility.php @@ -0,0 +1,45 @@ +, Leuchtfeuer Digital Marketing + */ + +namespace Leuchtfeuer\Auth0\Utility; + +use Psr\Http\Message\ServerRequestInterface; +use TYPO3\CMS\Core\Http\ApplicationType; +use TYPO3\CMS\Core\Information\Typo3Version; +use TYPO3\CMS\Core\Utility\GeneralUtility; + +class ModeUtility +{ + public const BACKEND_MODE = 'BE'; + public const FRONTEND_MODE = 'FE'; + + public static function isBackend(?string $mode=null): bool + { + if (!$mode) { + $mode = self::getModeFromRequest(); + } + + return $mode && $mode === self::BACKEND_MODE; + } + + public static function getModeFromRequest(): string + { + return ($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface + && ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend() + ? self::FRONTEND_MODE + : self::BACKEND_MODE; + } + + public static function isTYPO3V12(): bool + { + return version_compare(GeneralUtility::makeInstance(Typo3Version::class)->getVersion(), '12.0', '>='); + } +} diff --git a/Classes/Utility/ParametersUtility.php b/Classes/Utility/ParametersUtility.php index 66a7f5b3..66412978 100644 --- a/Classes/Utility/ParametersUtility.php +++ b/Classes/Utility/ParametersUtility.php @@ -11,7 +11,7 @@ * Florian Wessels , Leuchtfeuer Digital Marketing */ -namespace Bitmotion\Auth0\Utility; +namespace Leuchtfeuer\Auth0\Utility; class ParametersUtility { diff --git a/Classes/Utility/ParseFuncUtility.php b/Classes/Utility/ParseFuncUtility.php index 692dd7d9..04417968 100644 --- a/Classes/Utility/ParseFuncUtility.php +++ b/Classes/Utility/ParseFuncUtility.php @@ -11,9 +11,9 @@ * Florian Wessels , Leuchtfeuer Digital Marketing */ -namespace Bitmotion\Auth0\Utility; +namespace Leuchtfeuer\Auth0\Utility; -use Bitmotion\Auth0\Configuration\Auth0Configuration; +use Leuchtfeuer\Auth0\Configuration\Auth0Configuration; use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerAwareTrait; use TYPO3\CMS\Core\SingletonInterface; diff --git a/Classes/Utility/RoutingUtility.php b/Classes/Utility/RoutingUtility.php index 03e8aa76..58e8e1fb 100644 --- a/Classes/Utility/RoutingUtility.php +++ b/Classes/Utility/RoutingUtility.php @@ -11,7 +11,7 @@ * Florian Wessels , Leuchtfeuer Digital Marketing */ -namespace Bitmotion\Auth0\Utility; +namespace Leuchtfeuer\Auth0\Utility; use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerAwareTrait; diff --git a/Classes/Utility/TcaUtility.php b/Classes/Utility/TcaUtility.php index e8da57f6..63ce64c6 100644 --- a/Classes/Utility/TcaUtility.php +++ b/Classes/Utility/TcaUtility.php @@ -9,9 +9,9 @@ * Florian Wessels , Leuchtfeuer Digital Marketing */ -namespace Bitmotion\Auth0\Utility; +namespace Leuchtfeuer\Auth0\Utility; -use Bitmotion\Auth0\Configuration\Auth0Configuration; +use Leuchtfeuer\Auth0\Configuration\Auth0Configuration; use TYPO3\CMS\Core\Utility\GeneralUtility; class TcaUtility @@ -45,7 +45,7 @@ public function getColumnsFromTable(string $tableName): array if ($type === 'select') { $columns[$name]['items'] = []; foreach ($column['config']['items'] ?? [] as $item) { - $columns[$name]['items'][$item[1]] = $GLOBALS['LANG']->sl($item[0]); + $columns[$name]['items'][$item[1] ?? $item['value']] = $GLOBALS['LANG']->sl($item[0] ?? $item['label']); } } } diff --git a/Classes/Utility/TokenUtility.php b/Classes/Utility/TokenUtility.php index a3921b75..58621cd3 100644 --- a/Classes/Utility/TokenUtility.php +++ b/Classes/Utility/TokenUtility.php @@ -11,11 +11,8 @@ * Florian Wessels , Leuchtfeuer Digital Marketing */ -namespace Bitmotion\Auth0\Utility; +namespace Leuchtfeuer\Auth0\Utility; -use Bitmotion\Auth0\Domain\Transfer\EmAuth0Configuration; -use Bitmotion\Auth0\Exception\TokenException; -use Bitmotion\Auth0\Middleware\CallbackMiddleware; use DateTimeImmutable; use Lcobucci\JWT\Configuration; use Lcobucci\JWT\Signer; @@ -29,12 +26,13 @@ use Lcobucci\JWT\Validation\Constraint\IssuedBy; use Lcobucci\JWT\Validation\Constraint\PermittedFor; use Lcobucci\JWT\Validation\Constraint\SignedWith; +use Leuchtfeuer\Auth0\Domain\Transfer\EmAuth0Configuration; +use Leuchtfeuer\Auth0\Exception\TokenException; +use Leuchtfeuer\Auth0\Middleware\CallbackMiddleware; use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerAwareTrait; -use TYPO3\CMS\Core\Exception\SiteNotFoundException; use TYPO3\CMS\Core\Site\SiteFinder; use TYPO3\CMS\Core\Utility\GeneralUtility; -use TYPO3\CMS\Extbase\Service\EnvironmentService; class TokenUtility implements LoggerAwareInterface { @@ -156,29 +154,33 @@ public function getToken(): ?Token return $this->token; } - protected function setIssuer(): void + public function setIssuer(): void { - $environmentService = GeneralUtility::makeInstance(EnvironmentService::class); - - if ($environmentService->isEnvironmentInFrontendMode()) { + if (!ModeUtility::isBackend()) { try { + if (!$GLOBALS['TSFE']) { + $this->issuer = GeneralUtility::getIndpEnv('TYPO3_REQUEST_HOST'); + return; + } + $pageId = (int)$GLOBALS['TSFE']->id; $base = GeneralUtility::makeInstance(SiteFinder::class)->getSiteByPageId($pageId)->getBase(); if ($base->getScheme() !== null) { $this->issuer = sprintf('%s://%s', $base->getScheme(), $base->getHost()); - } else { - // Base of site configuration might be "/" so we have to retrieve the domain from the ENV - $this->issuer = GeneralUtility::getIndpEnv('TYPO3_REQUEST_HOST'); + return; } - } catch (SiteNotFoundException $exception) { + + // Base of site configuration might be "/" so we have to retrieve the domain from the ENV + $this->issuer = GeneralUtility::getIndpEnv('TYPO3_REQUEST_HOST'); + } catch (\Exception $exception) { $this->issuer = GeneralUtility::getIndpEnv('TYPO3_REQUEST_HOST'); } - $this->withPayload('environment', self::ENVIRONMENT_FRONTEND); - } elseif ($environmentService->isEnvironmentInBackendMode()) { - $this->issuer = GeneralUtility::getIndpEnv('TYPO3_REQUEST_HOST'); - $this->withPayload('environment', self::ENVIRONMENT_BACKEND); + + return; } + + $this->issuer = GeneralUtility::getIndpEnv('TYPO3_REQUEST_HOST'); } protected function getSigner(): Signer diff --git a/Classes/Utility/UserUtility.php b/Classes/Utility/UserUtility.php index b0656c3d..45ca08e2 100644 --- a/Classes/Utility/UserUtility.php +++ b/Classes/Utility/UserUtility.php @@ -11,15 +11,15 @@ * Florian Wessels , Leuchtfeuer Digital Marketing */ -namespace Bitmotion\Auth0\Utility; +namespace Leuchtfeuer\Auth0\Utility; use Auth0\SDK\Auth0; use Auth0\SDK\Utility\HttpResponse; -use Bitmotion\Auth0\Domain\Repository\ApplicationRepository; -use Bitmotion\Auth0\Domain\Repository\UserRepository; -use Bitmotion\Auth0\Domain\Transfer\EmAuth0Configuration; -use Bitmotion\Auth0\Utility\Database\UpdateUtility; use GuzzleHttp\Utils; +use Leuchtfeuer\Auth0\Domain\Repository\ApplicationRepository; +use Leuchtfeuer\Auth0\Domain\Repository\UserRepository; +use Leuchtfeuer\Auth0\Domain\Transfer\EmAuth0Configuration; +use Leuchtfeuer\Auth0\Utility\Database\UpdateUtility; use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerAwareTrait; use TYPO3\CMS\Backend\Utility\BackendUtility; diff --git a/Configuration/Backend/Modules.php b/Configuration/Backend/Modules.php new file mode 100644 index 00000000..e26c9d49 --- /dev/null +++ b/Configuration/Backend/Modules.php @@ -0,0 +1,25 @@ + [ + 'parent' => 'system', + 'position' => ['after' => 'web_info'], + 'access' => 'admin', + 'workspaces' => 'live', + 'iconIdentifier' => 'moduleAuth0', + 'path' => '/module/system/auth0', + 'labels' => 'LLL:EXT:auth0/Resources/Private/Language/locallang_mod.xlf', + 'extensionName' => 'auth0', + 'controllerActions' => [ + BackendController::class => 'list', + ApplicationController::class => 'list,delete', + RoleController::class => 'list,update', + PropertyController::class => 'list,new,create,edit,update,delete', + ], + ], +]; \ No newline at end of file diff --git a/Configuration/RequestMiddlewares.php b/Configuration/RequestMiddlewares.php index 1ec5bba7..c75d8c4d 100644 --- a/Configuration/RequestMiddlewares.php +++ b/Configuration/RequestMiddlewares.php @@ -1,10 +1,12 @@ [ - 'bitmotion/auth0/callback' => [ - 'target' => \Bitmotion\Auth0\Middleware\CallbackMiddleware::class, + 'leuchtfeuer/auth0/callback' => [ + 'target' => CallbackMiddleware::class, 'after' => [ 'typo3/cms-frontend/authentication', ], diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index b0cb313a..ff20f319 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -4,16 +4,16 @@ services: autoconfigure: true public: false - Bitmotion\Auth0\: + Leuchtfeuer\Auth0\: resource: '../Classes/*' - Bitmotion\Auth0\Command\CleanUpCommand: + Leuchtfeuer\Auth0\Command\CleanUpCommand: tags: - name: 'console.command' command: 'auth0:cleanupusers' description: 'Disable or remove obsolete website users.' - Bitmotion\Auth0\EventListener\AfterPackageActivation: + Leuchtfeuer\Auth0\EventListener\AfterPackageActivation: tags: - name: event.listener identifier: auth0AfterPackageActivationEvent diff --git a/Configuration/TCA/Overrides/be_groups.php b/Configuration/TCA/Overrides/be_groups.php index b8b544d4..e884d522 100644 --- a/Configuration/TCA/Overrides/be_groups.php +++ b/Configuration/TCA/Overrides/be_groups.php @@ -1,11 +1,15 @@ [ + AbstractUserGroupRepository::USER_GROUP_FIELD => [ 'exclude' => 1, 'label' => 'LLL:EXT:auth0/Resources/Private/Language/Database.xlf:fe_groups.auth0_user_group', 'config' => [ @@ -17,11 +21,11 @@ ] ); -\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes( - \Bitmotion\Auth0\Domain\Repository\UserGroup\BackendUserGroupRepository::TABLE_NAME, +ExtensionManagementUtility::addToAllTCAtypes( + BackendUserGroupRepository::TABLE_NAME, sprintf( '--div--;LLL:EXT:auth0/Resources/Private/Language/Database.xlf:tabs.auth0,%s', - \Bitmotion\Auth0\Domain\Repository\UserGroup\AbstractUserGroupRepository::USER_GROUP_FIELD + AbstractUserGroupRepository::USER_GROUP_FIELD ), '0', 'after:description' diff --git a/Configuration/TCA/Overrides/be_users.php b/Configuration/TCA/Overrides/be_users.php index 6029bbd8..e896ffb2 100644 --- a/Configuration/TCA/Overrides/be_users.php +++ b/Configuration/TCA/Overrides/be_users.php @@ -1,8 +1,10 @@ [ diff --git a/Configuration/TCA/Overrides/fe_groups.php b/Configuration/TCA/Overrides/fe_groups.php index f39e8263..ed5bbea3 100644 --- a/Configuration/TCA/Overrides/fe_groups.php +++ b/Configuration/TCA/Overrides/fe_groups.php @@ -1,11 +1,15 @@ [ + AbstractUserGroupRepository::USER_GROUP_FIELD => [ 'exclude' => 1, 'label' => 'LLL:EXT:auth0/Resources/Private/Language/Database.xlf:fe_groups.auth0_user_group', 'config' => [ @@ -17,11 +21,11 @@ ] ); -\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes( - \Bitmotion\Auth0\Domain\Repository\UserGroup\FrontendUserGroupRepository::TABLE_NAME, +ExtensionManagementUtility::addToAllTCAtypes( + FrontendUserGroupRepository::TABLE_NAME, sprintf( '--div--;LLL:EXT:auth0/Resources/Private/Language/Database.xlf:tabs.auth0,%s', - \Bitmotion\Auth0\Domain\Repository\UserGroup\AbstractUserGroupRepository::USER_GROUP_FIELD + AbstractUserGroupRepository::USER_GROUP_FIELD ), '0,Tx_Extbase_Domain_Model_FrontendUserGroup', 'after:description' diff --git a/Configuration/TCA/Overrides/fe_users.php b/Configuration/TCA/Overrides/fe_users.php index 8cb6c2de..1fc073ad 100644 --- a/Configuration/TCA/Overrides/fe_users.php +++ b/Configuration/TCA/Overrides/fe_users.php @@ -1,8 +1,10 @@ [ diff --git a/Configuration/TCA/Overrides/sys_template.php b/Configuration/TCA/Overrides/sys_template.php index 2586f01e..f94a89b1 100644 --- a/Configuration/TCA/Overrides/sys_template.php +++ b/Configuration/TCA/Overrides/sys_template.php @@ -1,8 +1,10 @@ isEnableFrontendLogin()) { - \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin( + ExtensionUtility::registerPlugin( 'Auth0', 'LoginForm', 'Auth0: Login form' @@ -24,7 +28,7 @@ $GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist']['auth0_loginform'] = 'pi_flexform'; $GLOBALS['TCA']['tt_content']['types']['list']['subtypes_excludelist']['auth0_loginform'] = 'layout,select_key,pages,recursive'; -\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue( +ExtensionManagementUtility::addPiFlexFormValue( 'auth0_loginform', 'FILE:EXT:auth0/Configuration/FlexForms/LoginForm.xml' ); diff --git a/Configuration/TCA/tx_auth0_domain_model_application.php b/Configuration/TCA/tx_auth0_domain_model_application.php index 76710089..d628953e 100644 --- a/Configuration/TCA/tx_auth0_domain_model_application.php +++ b/Configuration/TCA/tx_auth0_domain_model_application.php @@ -1,7 +1,7 @@ [ diff --git a/Documentation/About/Changelog/5-0-0.rst b/Documentation/About/Changelog/5-0-0.rst new file mode 100644 index 00000000..d5baf040 --- /dev/null +++ b/Documentation/About/Changelog/5-0-0.rst @@ -0,0 +1,47 @@ +.. include:: ../../Includes.txt + +========================== +Version 5.0.0 - 2023/09/11 +========================== + +This release is a major release, which will likely be breaking. Please be careful when upgrading to this version the namespace is changed from Bitmotion into Leuchtfeuer. +It introduces TYPO3 12.4 Support as well as support for PHP 7.4+. +We first concentrated on the functionality of the backend login with the help of Auth0 and refactored and restructured +most of it. + +Download +======== + +Download this version from the `TYPO3 extension repository `__ or from +`GitHub `__. + +Added +===== + +* Support for TYPO3 v12.4 + +Deprecated +========== + +Removed +======= + +* Support for TYPO3 v10 + +All Changes +=========== + +This is a list of all changes in this release:: + + 2023-09-08 [TASK]Remove unused files (Commit 1a1e811 by Yassine Abid) + 2023-09-08 [BUGFIX]Fix field naming in property form (Commit 241f0db by Yassine Abid) + 2023-09-08 [TASK]Adjust backend module icon (Commit 9f8f06f by Yassine Abid) + 2023-09-08 [BUGFIX]Fix field naming in property form (Commit 50f9cdf by Yassine Abid) + 2023-09-08 [TASK]Adjust backend module icon (Commit 74d52be by Yassine Abid) + 2023-09-08 [TASK]Adjust backend module for TYPO3V12 (Commit 2dc7137 by Yassine Abid) + 2023-09-07 [TASK]Backend login for 12 and remove support for 10 (Commit e8c641d by Yassine Abid) + 2023-09-07 [TASK]Remove Bitmotion as namespace (Commit 182928c by Yassine Abid) + 2023-09-06 [TASK]Process ext with rector for typo3 v11 and php74 (Commit fdb1685 by Yassine Abid) + 2023-09-06 [TASK]Make required libraries compatible for TYPO3 12; Require rector for dev environement (Commit 266ac14 by Yassine Abid) + +s \ No newline at end of file diff --git a/README.md b/README.md index 5cdd1fb1..fe020eff 100644 --- a/README.md +++ b/README.md @@ -20,14 +20,15 @@ The full documentation for the latest releases can be found [here](https://docs. You need access to an [Auth0](https://auth0.com/) instance. We are currently supporting following TYPO3 versions:

-| Extension Version | TYPO3 v11 Support | TYPO3 v10 Support | TYPO3 v9 Support | TYPO3 v8 Support | -| :-: | :-: | :-: | :-: | :-: | -| 4.x | x | x | - | - | -| 3.x | - | x | x | | -| 2.x | - | - | x | | -| 1.x | - | - | - | x | - -_Alpha support for TYPO3 v11.5 is available since version 4.0.0-alpha._ +| Extension Version | TYPO3 v12 Support | TYPO3 v11 Support | TYPO3 v10 Support | TYPO3 v9 Support | TYPO3 v8 Support | +|:-----------------:|:-----------------:|:-----------------:|:-----------------:|:----------------:|:----------------:| +| 5.x | x | x | - | - | - | +| 4.x | - | x | x | - | - | +| 3.x | - | - | x | x | | +| 2.x | - | - | - | x | | +| 1.x | - | - | - | - | x | + +_Alpha support for TYPO3 v12.4 is available since version 5.0.0-alpha._ ## About Auth0 Auth0 helps you to: diff --git a/Resources/Private/Layouts/LoginV12.html b/Resources/Private/Layouts/LoginV12.html new file mode 100644 index 00000000..3d37a269 --- /dev/null +++ b/Resources/Private/Layouts/LoginV12.html @@ -0,0 +1,139 @@ + + + + diff --git a/Resources/Private/Partials/Backend/Property/Form.html b/Resources/Private/Partials/Backend/Property/Form.html index 33d24c4f..40a88c85 100644 --- a/Resources/Private/Partials/Backend/Property/Form.html +++ b/Resources/Private/Partials/Backend/Property/Form.html @@ -9,7 +9,7 @@ - +
diff --git a/Resources/Private/Templates/BackendV11.html b/Resources/Private/Templates/LoginProvider/BackendV11.html similarity index 100% rename from Resources/Private/Templates/BackendV11.html rename to Resources/Private/Templates/LoginProvider/BackendV11.html diff --git a/Resources/Private/Templates/Backend.html b/Resources/Private/Templates/LoginProvider/BackendV12.html similarity index 85% rename from Resources/Private/Templates/Backend.html rename to Resources/Private/Templates/LoginProvider/BackendV12.html index 0b4e6211..0b10851d 100644 --- a/Resources/Private/Templates/Backend.html +++ b/Resources/Private/Templates/LoginProvider/BackendV12.html @@ -1,7 +1,5 @@ - - - + + @@ -27,7 +25,7 @@ {userInfo.nickname} 👋

- @@ -35,7 +33,7 @@

- {f:translate(key: 'LLL:EXT:auth0/Resources/Private/Language/locallang_be.xlf:form.not-logged-in') -> f:format.html()} + {f:translate(key: 'LLL:EXT:auth0/Resources/Private/Language/locallang_be.xlf:form.not-logged-in')}