ModifyRedirectUrlValidationResultEvent

New in version 13.2

With this event developers have the possibility to modify the validation results for the redirect URL, allowing redirects to URLs not matching the existing validation constraints.

The PSR-14 event \TYPO3\CMS\FrontendLogin\Event\ModifyRedirectUrlValidationResultEvent provides developers with the possibility and flexibility to implement custom validation for the redirect URL in the frontend login.

This may be useful, if TYPO3 frontend login acts as an SSO system, or if users should be redirected to an external URL after login.

Example: Validate that the redirect after frontend login goes to a trusted domain

EXT:my_extension/Classes/EventListeners/ValidateRedirectUrl.php
<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\EventListener;

use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\FrontendLogin\Event\ModifyRedirectUrlValidationResultEvent;

final readonly class ValidateRedirectUrl
{
    private const TRUSTED_HOST_FOR_REDIRECT = 'example.org';

    #[AsEventListener(
        identifier: 'validate-custom-redirect-url',
    )]
    public function __invoke(ModifyRedirectUrlValidationResultEvent $event): void
    {
        $parsedUrl = parse_url($event->getRedirectUrl());
        if ($parsedUrl['host'] === self::TRUSTED_HOST_FOR_REDIRECT) {
            $event->setValidationResult(true);
        }
    }
}
Copied!

New in version 13.0

API

class ModifyRedirectUrlValidationResultEvent
Fully qualified name
\TYPO3\CMS\FrontendLogin\Event\ModifyRedirectUrlValidationResultEvent

Allows to modify the result of the redirect URL validation (e.g. allow redirect to specific external URLs).

getRedirectUrl ( )
Returns
string
getValidationResult ( )
Returns
bool
setValidationResult ( bool $validationResult)
param $validationResult

the validationResult

getRequest ( )
Returns
\Psr\Http\Message\ServerRequestInterface