LogicException when redirecting to Keycloak

Created on 24 October 2023, 8 months ago
Updated 29 April 2024, about 2 months ago

Problem/Motivation

When using SSO with Keycloak the following error occurs when trying to redirect to an external URL:

LogicException: The controller result claims to be providing relevant cache metadata, but leaked metadata was detected. Please ensure you are not rendering content too early. Returned object class: Drupal\Core\Routing\TrustedRedirectResponse. in Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (line 154 of core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php).

Proposed resolution

The solution is to not use a TrustedRedirectResponse but a custom Response with a Location header.

$response = new Response(NULL, Response::HTTP_FOUND, ['Location' => $authorization_endpoint->getGeneratedUrl()]);
πŸ› Bug report
Status

Needs review

Version

2.2

Component

Code

Created by

πŸ‡¦πŸ‡ΉAustria daniel.pernold

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024