Problem/Motivation

Every login raises:

"RuntimeException: Failed to start the session because headers have already been sent by "/var/www/Currents-D9/vendor/symfony/http-foundation/Response.php" at line 368. in Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage->start() (line 152 of /var/www/Currents-D9/vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php)"

from ...o365/callback.

Despite the error, all logins are all successful.

Steps to reproduce

Login -- redirect /user/login to o365 login is checked in settings.

Issue fork o365-3312108

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

frymorgan created an issue. See original summary.

  • fabianderijk committed 074503b on 3.0.x
    Issue #3312108: RuntimeException: Failed to start the session because...
fabianderijk’s picture

Status: Active » Fixed

This is now fixed in the dev release and in the upcoming tagged release.

phma’s picture

Status: Fixed » Needs work

I came across this issue investigating why the destination parameter is still being ignored #3152353: Redirect to destination URL after login and noticed that the session was only saved after headers have been sent already.

I'm surprised by your approach, because how would it be able to save the "destination" in the session/tempstore if you just terminate the request right away? I haven't tried your solution yet to be honest so I might be missing something, but I was able to fix it temporarily by passing the response upstream instead of sending it on the spot.

I love this project and it does a great job providing SSO for our site. But without any test coverage and community review before changes are being pushed, I'm somewhat hesitant to keep using it in production. Let me know if there's any way I could help to improve this.

EDIT: After doing more testing I found out that if I return the response, it's actually redirecting to "destination" without logging in. But in order for the destination to be picked up, I need to save the session before I send the response and terminate the request. Else "destination" is ignored, because a new session is created when returning back to the site.

    $response = new TrustedRedirectResponse($authUrl);
    $this->request->getSession()->save();
    $response->send();
    exit();
timlie’s picture

Hi,

This does indeed fix the problem.
There are some different approaches found, like here:

https://www.drupal.org/project/drupal/issues/2852657#comment-14151263

timlie’s picture

Actually I was to fast.
The errors are gone but the access token is not saved to the temp store.

fabianderijk’s picture

Status: Needs work » Needs review

Thanks for the help and the pointers. I've just created a MR which includes the code from @phma. You can review this.

@phma, regarding the help. You are always welcome in helping this module grow both in usage as in maturity. We are planning to add some test coverage to this module, if you are inclined to help, this would be our main focus for the foreseeable future.

fabianderijk’s picture

Assigned: Unassigned » mikechan
phma’s picture

Status: Needs review » Reviewed & tested by the community

@fabianderijk Thanks for creating the MR. I never go around doing it myself. Also, our website no longer needs the destination parameter to work so desperately. Still, I've applied the patch on our site and can confirm that it is working locally on my machine. At least I can help others, and it will be working if our site ever requires it.

As I'm changing roles soon, my focus is going to shift, and I'm probably no longer able to help you guys, sorry. But I hope I can continue to contribute in some ways in the future. In the meantime, keep up the good work!

I'm marking this as RTBC, but feel free to change it back if you want someone else to test it.

  • fabianderijk committed d3f39736 on 3.0.x
    Issue #3312108 by fabianderijk, phma: RuntimeException: Failed to start...

  • fabianderijk committed 5c0c0ed4 on 5.0.x
    Issue #3312108 by fabianderijk, phma: RuntimeException: Failed to start...
fabianderijk’s picture

Status: Reviewed & tested by the community » Fixed

This has now been added to the 3.0.x branch dev release, and is added to the new 5.0.0 release tag

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.