Problem/Motivation
Retrieving token raises
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).
Steps to reproduce
'Get auth token' button at /admin/config/system/phpmailer-oauth2
Proposed resolution
Patch MSLoginController (47): 'redirect_uri' => Url...->tostring(TRUE) so it contains a GeneratedUrl object.
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | leaked_metadata-3344088-11.patch | 1.21 KB | frymorgan |
| #2 | leaked_metadata-3344088-2.patch | 633 bytes | frymorgan |
Comments
Comment #2
frymorgan commentedPatch to the above effect.
Comment #3
imclean commentedIs the return type the same? Or should it be:
'redirect_uri' => Url::fromRoute('phpmailer_oauth2.settings')->setAbsolute()->toString(TRUE)->getGeneratedUrl()Comment #4
imclean commentedComment #5
frymorgan commentedUrl::toString(TRUE) returns a GeneratedUrl object, appending getGeneratedUrl() will return a string.
NB, the previous version (before the change in #3316295), after this patch also works. (Drupal 9.5, PHP 8.1)
With
redirect_uri' => Url::fromRoute('phpmailer_oauth2.settings')->setAbsolute()->toString(TRUE)->getGeneratedUrl(), Azure returns an error because /admin/config/system/phpmailer-oauth2 is not the callback url defined in the Azure app.Comment #6
imclean commentedWhich is what is returned without this patch.
How does adding "TRUE" fix the error? It's the same (incorrect?) route being returned, just as a GeneratedUrl object instead of a string.
Comment #7
nathan tsai commentedIncreasing the priority of this issue to "Major" because the module is currently unusable without a workaround.
I got the same error as above, but applying the patch allowed me to successfully generate the tokens:
I have no clue why returning a GeneratedUrl fixes the bug, though, hence the "Needs Review" status.
@frymorgan, perhaps you can speak more about this issue?
Comment #9
imclean commentedI don't fully understand why as we've used this module in the past without it. That said, it works for at least 2 people so I've committed it.
Comment #11
frymorgan commentedUsing getGeneratedUrl() is correct after all. Problem was the route should be phpmailer_oauth2.aad_callback, not phpmailer_oauth2.settings.
As it stands, it does not insert a redirect_url into the response at all, which works if the Azure app has only one Redirect URI.