Skip to content

Commit

Permalink
[TASK] Restructure backend TypoScript
Browse files Browse the repository at this point in the history
  • Loading branch information
flossels committed Jun 12, 2020
1 parent a0fb447 commit a59302d
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 59 deletions.
5 changes: 4 additions & 1 deletion Classes/Controller/ApplicationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
use Bitmotion\Auth0\Domain\Model\Application;
use Bitmotion\Auth0\Domain\Transfer\EmAuth0Configuration;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Extbase\Mvc\Exception\StopActionException;

class ApplicationController extends BackendController
{
public function listAction(): void
{
$pid = (new EmAuth0Configuration())->getUserStoragePage();
$pid = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK, 'auth0')['persistence']['storagePid']
?? (new EmAuth0Configuration())->getUserStoragePage();

$this->view->assignMultiple([
'applications' => $this->applicationRepository->findAll(),
'pid' => $pid,
Expand Down
36 changes: 20 additions & 16 deletions Classes/LoginProvider/Auth0Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@
use Bitmotion\Auth0\Factory\SessionFactory;
use Bitmotion\Auth0\Middleware\CallbackMiddleware;
use Bitmotion\Auth0\Utility\ApiUtility;
use Bitmotion\Auth0\Utility\ConfigurationUtility;
use Bitmotion\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\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Fluid\View\StandaloneView;

class Auth0Provider implements LoginProviderInterface, LoggerAwareInterface
Expand Down Expand Up @@ -61,6 +63,17 @@ class Auth0Provider implements LoginProviderInterface, LoggerAwareInterface
*/
protected $action;

/**
* @var array
*/
protected $frameworkConfiguration;

public function __construct()
{
$configurationManager = GeneralUtility::makeInstance(ObjectManager::class)->get(ConfigurationManager::class);
$this->frameworkConfiguration = $configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK, 'auth0');
}

/**
* @throws InvalidConfigurationTypeException
*/
Expand Down Expand Up @@ -170,28 +183,19 @@ protected function handleRequest(): void

protected function isTypoScriptLoaded(): bool
{
try {
ConfigurationUtility::getSetting('propertyMapping');
} catch (\Exception $exception) {
$this->logger->notice($exception->getMessage());

return false;
}

return true;
return isset($this->frameworkConfiguration['settings']['stylesheet']);
}

/**
* @throws InvalidConfigurationTypeException
*/
protected function prepareView(StandaloneView &$standaloneView, PageRenderer &$pageRenderer): void
{
$backendViewSettings = ConfigurationUtility::getSetting('backend', 'view');
$standaloneView->setLayoutRootPaths([$backendViewSettings['layoutPath']]);
$standaloneView->setTemplatePathAndFilename(
GeneralUtility::getFileAbsFileName($backendViewSettings['templateFile'])
);
$pageRenderer->addCssFile($backendViewSettings['stylesheet']);
$standaloneView->setTemplate('Backend');
$standaloneView->setLayoutRootPaths($this->frameworkConfiguration['view']['layoutRootPaths']);
$standaloneView->setTemplateRootPaths($this->frameworkConfiguration['view']['templateRootPaths']);

$pageRenderer->addCssFile($this->frameworkConfiguration['settings']['stylesheet']);
}

protected function getDefaultView(StandaloneView &$standaloneView, PageRenderer &$pageRenderer): void
Expand Down
9 changes: 8 additions & 1 deletion Configuration/TypoScript/constants.typoscript
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ plugin.tx_auth0 {
storagePid =
}

# These frontend constants are deprecated and will be removed in next major version of this extension
settings {
backend {
view {
Expand All @@ -18,7 +19,6 @@ plugin.tx_auth0 {
}
}

# These frontend constants are deprecated and will be removed in next major version of this extension
frontend {
callback {
targetPageType = 1547536919
Expand All @@ -35,3 +35,10 @@ plugin.tx_auth0 {
}
}

module.tx_auth0 {
view {
templateRootPath = EXT:auth0/Resources/Private/Templates/
layoutRootPath = EXT:auth0/Resources/Private/Layouts/
}
persistence.storagePid = 1
}
28 changes: 25 additions & 3 deletions Configuration/TypoScript/setup.typoscript
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ plugin.tx_auth0 {
persistence.storagePid = {$plugin.tx_auth0.persistence.storagePid}

settings {
# The backend settings are deprecated. Please use module.tx_auth0.view instead
backend {
view {
layoutPath = {$plugin.tx_auth0.settings.backend.view.layoutPath}
templateFile = {$plugin.tx_auth0.settings.backend.view.templateFile}
stylesheet = {$plugin.tx_auth0.settings.backend.view.stylesheet}
}
}
Expand Down Expand Up @@ -50,8 +50,9 @@ plugin.tx_auth0 {
}

# maps auth0 roles to TYPO3 fe_groups or be_groups
# the roles configuration via TypoScript is deprecated. Please use the dedicated backend
# The roles configuration via TypoScript is deprecated. Please use the dedicated backend
# module for configuring the roles. You can easily import your TypoScript settings there.
# See: https://docs.typo3.org/p/leuchtfeuer/auth0/master/en-us/Admin/Module/Index.html
roles {
key = {$plugin.tx_auth0.settings.roles.key}

Expand All @@ -72,6 +73,9 @@ plugin.tx_auth0 {
}
}

# The property Mapping configuration via TypoScript is deprecated. Please use the dedicated backend
# module for configuring the roles. You can easily import your TypoScript settings there.
# See: https://docs.typo3.org/p/leuchtfeuer/auth0/master/en-us/Admin/Module/Index.html
propertyMapping {
be_users {
username = nickname
Expand Down Expand Up @@ -105,6 +109,7 @@ plugin.tx_auth0 {
}

# This page type is marked as deprecated and will be removed in next major version of this extension
# Please use the generic callback instead: https://docs.typo3.org/p/leuchtfeuer/auth0/master/en-us/Admin/Callback/Index.html
auth0_callback = PAGE
auth0_callback {
typeNum = 1547536919
Expand All @@ -119,4 +124,21 @@ auth0_callback {
10 =< tt_content.list.20.auth0_loginform
}

module.tx_auth0 < plugin.tx_auth0
module.tx_auth0 {
view {
layoutRootPaths {
0 = EXT:auth0/Resources/Private/Layouts/
1 = {$module.tx_auth0.view.layoutRootPath}
2 = {$plugin.tx_auth0.settings.backend.view.layoutPath}
}

templateRootPaths {
0 = EXT:auth0/Resources/Private/Templates/
1 = {$module.tx_auth0.view.templateRootPath}
}
}

persistence.storagePid = {$module.tx_auth0.persistence.storagePid}

settings.stylesheet = {$module.tx_auth0.settings.stylesheet}
}
9 changes: 4 additions & 5 deletions Documentation/Admin/Migrations/BackendModule.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ settings.
2. Migrate the role mapping

Navigate into the Auth0 backend module and click on the "configure" button in the "Roles to Groups" card. There should be an
info box on top of the content. Click on the "Import configuration from TypoScript" button. After the page refreshed, the
module will output the configuration migrated from you TypoScript.
Navigate into the Auth0 :ref:`backend module <admin-module>` and click on the "configure" button in the "Roles to Groups"
card. There should be an info box on top of the content. Click on the "Import configuration from TypoScript" button. After
the page refreshed, the module will output the configuration migrated from you TypoScript.

.. figure:: ../../Images/migrate-backend-module.png
:alt: The backend module.
Expand All @@ -47,5 +47,4 @@ settings.
plugin.tx_auth0.settings.roles >
plugin.tx_auth0.settings.propertyMapping >
Do not forget to let the :typoscript:`module.tx_auth0` configuration extend the :typoscript:`plugin.tx_auth0` configuration.
Afterwards the info boxes in the backend module should be disappeared.
Do not forget to remove the configuration you made in 1. Afterwards the info boxes in the backend module will disappear.
43 changes: 10 additions & 33 deletions Documentation/Admin/TypoScript/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,43 +31,19 @@ You have also the option to use your own template files for the backend login. J

.. code-block:: typoscript
plugin.tx_auth0.settings.backend.view {
layoutPath = EXT:your_key/Resources/Private/Layouts/
templateFile = EXT:your_key/Resources/Private/Templates/Backend.html
stylesheet = EXT:your_key/Resources/Public/Styles/Backend.css
}
Please make also sure that you configure the :ref:`role mapping <admin-typoscript-roleMapping>` from Auth0 roles to TYPO3 user groups. Maybe you also want to set the admin
flag for backend users, depending on an Auth0 :ref:`role mapping <admin-typoscript-propertyMapping>`.

.. _admin-typoscript-loginBehaviour:

Login Behaviour
===============

Configure whether disabled or deleted frontend or backend users should be able to login by adapting the following TypoScript
constants:

.. code-block:: typoscript
plugin.tx_auth0.settings.reactivateUsers {
be_users {
# if active, sets the disable flag to 0 when user tries to login again
disabled = 0
# if active, sets the deleted flag to 0 when user tries to login again
deleted = 0
module.tx_auth0 {
view {
layoutPath = EXT:your_key/Resources/Private/Layouts/
templatePath = EXT:your_key/Resources/Private/Templates/
}
fe_users {
# if active, sets the disable flag to 0 when user tries to login again
disabled = 1
# if active, sets the deleted flag to 0 when user tries to login again
deleted = 1
}
settings.stylesheet = EXT:your_key/Resources/Public/Styles/Backend.css
}
Please make also sure that you configure the :ref:`role mapping <admin-typoscript-roleMapping>` from Auth0 roles to TYPO3 user
groups. Maybe you also want to set the admin flag for backend users, depending on an Auth0
:ref:`role mapping <admin-typoscript-propertyMapping>`.

.. _admin-typoscript-frontendSettings:

Frontend Settings
Expand Down Expand Up @@ -209,3 +185,4 @@ Function Description
`bool` Get the boolean value.
`strtotime` Parse about any English textual datetime description into a Unix timestamp.
`negate` Negate the value (only for booleans).
=========== ===========================================================================

0 comments on commit a59302d

Please sign in to comment.