LogicException when redirecting to Keycloak

Created on 24 October 2023, about 1 year 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

Active

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.71.5 2024