Search code examples
phptypo3extbasetypo3-extensionstypo3-10.x

TYPO3 - Access settings in AuthenticationService


I do develop a little extension for a TYPO3 v10 where I need to gain access to the my extension-settings in a service class that extends \TYPO3\CMS\Core\Authentication\AuthenticationService.

My first attemp was to pass the settings using the DI configured in my Services.yaml according to: https://daniel-siepmann.de/concrete-typo3-dependency-injection-examples.html (Inject Extension Configuration)

However no matter what I do the settings array passed to my __constructor(array $settings) stays empty.

Then I tried to go for a more hacky attemp like:

public function __construct(array $settings)
    {
        $this->settings = $settings;
        DebuggerUtility::var_dump($this->settings);

        $configurationManager = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Configuration\ConfigurationManager::class);
        $typoscript = $configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
        
        DebuggerUtility::var_dump($typoscript);
        die('debug');
    }

But also loading the the full typoscript seems to fail since $typoscript is also null. Therefore I think that is has to do something with the AuthenticationService that my class extends? How can I gain access to my settings when extending TYPO3's AuthenticationService?


Solution

  • When the AuthenticationService is consulted for FE or BE login, typoscript is not available yet, as authentication happens early in the middleware stack (have a look at the order of the PSR-15 middlewares in the configuration module of the backend).

    This is because typoscript is page dependend and whether you are eligible to access a page may be dependend on you login status or user roles.

    So the question would be what kind of settings are you trying to access? You could use the site configuration (that is already loaded for authentication) or you could use global configuration in TYPO3_CONF_VARS that is always available.