BeforeRequestTokenProcessedEvent

New in version 12.1

The event \TYPO3\CMS\Core\Authentication\Event\BeforeRequestTokenProcessedEvent allows to intercept or adjust a request token during active user authentication process.

Example

The event can be used to generate the request token individually. This can be the case when you are not using a login callback and have not the possibility to submit a request token:

EXT:my_extension/Classes/Authentication/EventListener/MyEventListener.php
<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\Authentication\EventListener;

use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Core\Authentication\Event\BeforeRequestTokenProcessedEvent;
use TYPO3\CMS\Core\Security\RequestToken;

#[AsEventListener(
    identifier: 'my-extension/process-request-token-listener',
)]
final readonly class MyEventListener
{
    public function __invoke(BeforeRequestTokenProcessedEvent $event): void
    {
        $user = $event->getUser();
        $requestToken = $event->getRequestToken();
        // fine, there is a valid request token
        if ($requestToken instanceof RequestToken) {
            return;
        }

        // Validate individual requirements/checks
        // ...
        $event->setRequestToken(
            RequestToken::create('core/user-auth/' . strtolower($user->loginType)),
        );
    }
}
Copied!

New in version 13.0

The PHP attribute \TYPO3\CMS\Core\Attribute\AsEventListener has been introduced to tag a PHP class as an event listener. Alternatively, or if you need to be compatible with older TYPO3 versions, you can also register an event listener via the Configuration/Services.yaml file. Switch to an older version of this page for an example or have a look at the section Implementing an event listener in your extension.

API

class \TYPO3\CMS\Core\Authentication\Event\ BeforeRequestTokenProcessedEvent

Event fired before request-token is processed.

getUser ( )
returntype

TYPO3\CMS\Core\Authentication\AbstractUserAuthentication

getRequest ( )
returntype

Psr\Http\Message\ServerRequestInterface

getRequestToken ( )
returntype

TYPO3\CMS\Core\Security\RequestToken|false|null

setRequestToken ( TYPO3\\CMS\\Core\\Security\\RequestToken|false|null $requestToken)
param TYPO3\\CMS\\Core\\Security\\RequestToken|false|null $requestToken

the requestToken