I'm seeing two exceptions thrown every time a user is redirected to a provider for login. They are similar to the ones reported in #2990036 but not exactly the same. I have tested with an implementation we developed (Social Auth PBS) and the Github implementation.

Whenever a user hits the callback URL (e.g. /user/login/pbs or /user/login/github) the following two exceptions are logged --

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 [...]/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php).

RuntimeException: Failed to start the session because headers have already been sent by "[...]/vendor/symfony/http-foundation/Response.php" at line 1286. in Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage->start() (line 141 of [...]/vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php) 
    #0 [...]/docroot/core/lib/Drupal/Core/Session/SessionManager.php(164): Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage->start() 
    #1 [...]/docroot/core/lib/Drupal/Core/Session/SessionManager.php(195): Drupal\Core\Session\SessionManager->startNow() 
    #2 [...]/vendor/symfony/http-foundation/Session/Session.php(196): Drupal\Core\Session\SessionManager->save() 
    #3 [...]/docroot/core/lib/Drupal/Core/StackMiddleware/Session.php(60): Symfony\Component\HttpFoundation\Session\Session->save() 
    #4 [...]/docroot/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
    #5 [...]/docroot/core/modules/page_cache/src/StackMiddleware/PageCache.php(184): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
    #6 [...]/docroot/core/modules/page_cache/src/StackMiddleware/PageCache.php(121): Drupal\page_cache\StackMiddleware\PageCache->fetch(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
    #7 [...]/docroot/core/modules/page_cache/src/StackMiddleware/PageCache.php(75): Drupal\page_cache\StackMiddleware\PageCache->lookup(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
    #8 [...]/docroot/modules/contrib/jsonapi/src/StackMiddleware/FormatSetter.php(41): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
    #9 [...]/docroot/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\jsonapi\StackMiddleware\FormatSetter->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
    #10 [...]/docroot/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
    #11 [...]/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
    #12 [...]/docroot/core/lib/Drupal/Core/DrupalKernel.php(693): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) 
    #13 [...]/docroot/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request)) 
    #14 {main}.

The exceptions appear to be triggered somewhere in \Drupal\social_auth\Controller\OAuth2ControllerBase::redirectToProvider() but I haven't been able to troubleshoot very far. I don't think this was happening before 8.x-2.0-beta5, but I'm not 100% sure of that.

Comments

wells created an issue. See original summary.

wells’s picture

Oh and to be clear -- this doesn't appear to prevent any functionality. I only noticed the log entries while looking in to something unrelated. Login for new and existing users works fine.

wells’s picture

Issue summary: View changes
wells’s picture

Version: 8.x-2.0-beta5 » 8.x-2.x-dev
StatusFileSize
new5.45 KB

I dug up a detailed write up from Lullabot for the LogicException and sorted out that this happens because the URL generation process adds cacheable metadata to the response. See: Early Rendering: A Lesson in Debugging Drupal 8.

The attached patch uses the approach outlined in that article to capture and bubble up the metadata with \Drupal\social_auth\Controller\OAuth2ControllerBase::redirectToProvider()'s TrustedRedirectResponse but it seems that this would still be an API change requiring changes to implementors because OAuth2ControllerBase needs to inject the \Drupal\Core\Render\Renderer service. E.g. to test this with Social Auth Github I had to modify GitHubAuthController to inject Renderer for it's parent::__construct call.

wells’s picture

Status: Active » Needs review
StatusFileSize
new6.24 KB
new4.16 KB

One small change to my patch in #4 -- I moved the try ... catch block for PluginException inside executeInRenderContext so that exception can actually be picked up.

shaundychko’s picture

shaundychko’s picture

When using social_auth_google the errors reported here prevented logging in. I had to downgrade back to beta-4.

shaundychko’s picture

A little patch review:

At $response = \Drupal::service('renderer')->executeInRenderContext($context, function() {
The class property $renderer should be used.

wells’s picture

D'oh! Whole reason for making API changes (:

Thanks for catching that. Updated patch attached.

gvso’s picture

Thank you for this! I will be reviewing the provided documentation and patch this week. Even if this is not what I wanted, we might not have other options than to change the API to include the renderer.

@ShaunDychko, you got errors when using Social Auth Google? I've been testing Social Auth Google, and it works fine for me. What Drupal version are you using?

shaundychko’s picture

@gvso I'm using the latest 8.6.9, and was also using 8.6.7. I included more DB log output in the duplicate issue I originally reported at #3033225: Logic Exception and RuntimeException after upgrade to beta-4. I'm also running PHP 7.2.

proxiss’s picture

@gvso I got errors with Social Auth Google, too. These are hard to clarify. Completely new (for Google) users do work (on registration), some old Google users do not work (null Exception on registration and login), some old users do work (on login).
Version is 8.6.9 (upgraded from working 8.6.2), drupal/social_api 2.0.0-beta5, drupal/social_auth 2.0.0-beta5, drupal/social_auth_google 2.0.0-beta4, league/oauth2-google 3.0.1.

gvso’s picture

Priority: Normal » Major
StatusFileSize
new6.53 KB
new2.1 KB

I updated the patch. No much changes, but I fix coding standard violations.

I also upload a patch for Social Auth Google for testing. Please, let me know if this works since I consider this a major issue if Social Auth Google stopped working.

Status: Needs review » Needs work

The last submitted patch, 13: social-auth-google-3033444-13.patch, failed testing. View results

shaundychko’s picture

The two patches above fixed the 2 DB log errors that occurred upon redirect to Google.
However, returning back to the site at /user/login/google/callback results in the following fatal error:

Referrer	https://accounts.google.ca/accounts/SetSID
Message	LogicException: The controller must return a response (null given). Did you forget to add a return statement somewhere in your controller? in Symfony\Component\HttpKernel\HttpKernel->handleRaw() (line 169 of /app/vendor/symfony/http-kernel/HttpKernel.php).
shaundychko’s picture

"fatal error" means white screen of death with the message

The website encountered an unexpected error. Please try again later.
gvso’s picture

Hmm. Would you mind sharing your set up? I am using Drupal 8.6 and Apache when testing this.

shaundychko’s picture

The issue is a conflict with another module I have installed, but despite hours coming to that conclusion I haven't figured out which one. With the patches in #13, things work fine on a clean install.

As for your question about my setup, I created https://github.com/ShaunDychko/test-social-auth so that you could have the exact same setup on Platform.sh. I made that repo with the intention for you to see the error, but in fact it works fine.

I don't have an issue with module conflicts on the beta-3 version of social_auth_google (using my fork at https://github.com/ShaunDychko/social_auth_google to have league/oauth2-google:^3.0, and corresponding beta version of the other social_* modules), so I'll stick to that for now, but maybe find time later to investigate further which module is conflicting.

gvso’s picture

Status: Needs work » Needs review

Cool. It'd be nice to see if this works for others as well.

shaundychko’s picture

Latest update is that there's no module conflict. The issue is solved when I use Devel's "Reinstall Module" for social_auth. It's not enough to reinstall social_auth_google. Since this requires deleting all social_auth entities, it's not a viable solution for the production site, so I suppose the mystery continues...

wells’s picture

@gvso, I finally got around to testing your patches and they work for a fresh install for me. I don't have any services using SA Google in production and I couldn't replicate @ShaunDychko's issue with just my test data.

@ShaunDychko, I wonder if there is any way you can replicate the problematic site setup without exposing sensitive data? Curious to see why the reinstall might have helped as the changes are really pretty minor.

shaundychko’s picture

@wells, I've tested a fresh install with the same setup I'm currently using in production (matching beta versions), succeeded in creating an account via Google, then updated to the latest dev. along with patches from #13, and had bitter-sweet success. The upgrade path seems to be fine, but upgrading nevertheless fails on my production site.

spokje’s picture

FWIW:

- I've successfully applied both patches in #13.
- Both Exceptions didn't appear on both registering and log-in after patching, they where there before.
- Didn't experience the Fatal Error mentioned by @ShaunDychko
- Obviously the patch on social_auth breaks other depending modules like social_auth_facebook and social_auth_twitter with a nice WSOD on ArgumentCountError: Too few arguments to function Drupal\social_auth\Controller\OAuth2ControllerBase::__construct(), 8 passed in /app/web/modules/contrib/social_auth_facebook/src/Controller/FacebookAuthController.php on line 42 and exactly 9 expected in Drupal\social_auth\Controller\OAuth2ControllerBase->__construct() (line 107 of /app/web/modules/contrib/social_auth/src/Controller/OAuth2ControllerBase.php)
(The above is a social_auth_facebook example)

Note:

I applied the patches on "drupal/social_auth": "2.0-beta5" and "drupal/social_auth_google": "2.0-beta4" so _not_ on the dev versions.

ndf’s picture

#23 That WSOD ArgumentCountError: Too few arguments should be fixed here I think too. With semantic versioning, this is probably a BC-break that needs a higher version.

+++ b/src/Controller/OAuth2ControllerBase.php
@@ -92,6 +101,8 @@ class OAuth2ControllerBase extends ControllerBase {
@@ -100,7 +111,8 @@ class OAuth2ControllerBase extends ControllerBase {

@@ -100,7 +111,8 @@ class OAuth2ControllerBase extends ControllerBase {
                               UserAuthenticator $user_authenticator,
                               OAuth2ManagerInterface $provider_manager,
                               RequestStack $request,
-                              SocialAuthDataHandler $data_handler) {
+                              SocialAuthDataHandler $data_handler,
+                              RendererInterface $renderer) {

For backwards compatibility RendererInterface $renderer = NULL is better here.

+++ b/src/Controller/OAuth2ControllerBase.php
@@ -125,49 +138,62 @@ class OAuth2ControllerBase extends ControllerBase {
+    /** @var \Drupal\Core\Routing\TrustedRedirectResponse|\Symfony\Component\HttpFoundation\RedirectResponse $response */
+    $response = $this->renderer->executeInRenderContext($context, function () {
...
-      $response = new TrustedRedirectResponse($auth_url);

The removed line could be the default value of $response if $renderer is NULL.

And I think a proper automated test would help a lot here to prevent issues like this in the future.

wells’s picture

Does the approach suggested in #24 make sense if the exceptions are breaking logins in some cases anyway (see #7)? In my case this would help because the error doesn't actually prevent login or registration, but for others supporting a nullable renderer may just confuse things. But maybe that is still preferable to a WSOD... if we did do that, should we catch the exceptions and write something about updating the provider module to the site log? I'm not sure how/if it is possible to determine if the result is a completely failed login or just the exceptions being logged.

gvso’s picture

Does the approach suggested in #24 make sense if the exceptions are breaking logins in some cases anyway (see #7)?

I was thinking that this might be an issue, but I was also thinking of adding backward compatibility by using \Drupal::service() if NULL. We can then remove this change later.

wells’s picture

Ah, yeah I think that approach makes sense and is much simpler than trying to catch exceptions or sort out breakage level.

gvso’s picture

StatusFileSize
new6.82 KB
m.lebedev’s picture

Hi! I have a problem when a auth path has value "/user/login/google?destination=/some". The destination parameter does not allow to auth. I used patches #13 and #27.

Also I use require_login module. After apply the patch patch #13 or #27 I started getting problems. If I delete require_login module then auth works as usual.

I found that earlier...

  public function redirectToProvider() {

    try {
      /* @var \League\OAuth2\Client\Provider\AbstractProvider|false $client */
      $client = $this->networkManager->createInstance($this->pluginId)->getSdk();
....
      $response->send(); // << --- this was the reason to go to auth

      return $response;
    }
gvso’s picture

@m.lebedev, does this happens with Nginx? That was introduced in #2981737: Destination parameter forbids user to be redirected for authentication

m.lebedev’s picture

Yes, it does. I use nginx + php-fpm. There is the same problem

wells’s picture

I applied and tested #28 successfully for both providers with the renderer service injected and without. Tested providers were PBS, GitHub and Slack. No dblog messages and login worked fine.

I’ll leave this to someone else to confirm with a Google oauth flow before we go RTBC.

ndf’s picture

Status: Needs review » Reviewed & tested by the community

I also applied #28 and tested with social_auth_google 8.x-2.0-beta4
Messages are gone, works perfect.

I also read through social_auth/src/Controller/OAuth2ControllerBase.php
Although I don't understand everything the class seems very well documented and formatted.

So here we go: RTBC

gvso’s picture

Status: Reviewed & tested by the community » Needs work

Thanks everyone! We still need to fix the issue with Nginx. I don't know if that would break the current solution. I'll have to try

gvso’s picture

Status: Needs work » Needs review
StatusFileSize
new7.5 KB
new1.97 KB

I think this might solve all the warnings and errors.

wells’s picture

Hm, I'm inclined to think that should be taken up in a separate issue. I also wonder if this is really the place to be fixing this? I can't find a clear reference for this at the moment, but my understanding is that modules should never be using $response->send(); directly, only returning a response to be sent by the kernel.

gvso’s picture

StatusFileSize
new7.35 KB
new587 bytes

It turned out, I couldn't reproduce the bug as I used to do with the issue I referenced to. I removed the save method anyways since it's no longer used.

@m.lebedev, can you test this patch? I tested it with Nginx + PHP-FPM and by adding destination parameters.

eahonet’s picture

I can now login with an existing user, but cannot create users as it used to do before updating.

I've tried patches #13 #28 #35

I do use composer.

        "drupal/social_api": "^2.0",
        "drupal/social_auth": "^2.0",
        "drupal/social_auth_google": "^2.0",
           "drupal/social_auth": {
            "fix google login": "https://www.drupal.org/files/issues/2019-03-07/3033444-35.patch"
          },

I have turned on that visitors can create accounts. I've uninstalled require_login and swiftmailer.

When I try to login with Google, I get to enter in my google user/pass, and when it goes back to my site, it gives me the below (only on non-existing users)

The website encountered an unexpected error. Please try again later.</br></br><em class="placeholder">LogicException</em>: The controller must return a response (null given). Did you forget to add a return statement somewhere in your controller? in <em class="placeholder">Symfony\Component\HttpKernel\HttpKernel-&gt;handleRaw()</em> (line <em class="placeholder">169</em> of <em class="placeholder">/home/[user]/sites/main/vendor/symfony/http-kernel/HttpKernel.php</em>).

wells’s picture

@eahonet, did you try the patch in #37? And can you tell us more about your setup? I just tested successfully with a fresh, patched installed of Social Auth with the Github and Slack providers -- new users were created and no errors given.

gvso’s picture

If I delete require_login module then auth works as usual.

I've uninstalled require_login and swiftmailer.

It seems like there's a conflict with require_login and Social Auth

m.lebedev’s picture

it still does not work with the destionation parameter. (nginx)

m.lebedev’s picture

StatusFileSize
new9.6 KB

The request is sent when I go to the auth path. The request is correct.
after that, redirection occurs to the destination.
the require_login checks the path that is forbidden to go to anonymous users and the require_login redirects on the login page.
example

eahonet’s picture

Update from me. I am running up to date versions of

        "drupal/social_api": "^2.0",
        "drupal/social_auth": "^2.0",
        "drupal/social_auth_google": "^2.0",

And the patch from #37

"drupal/social_auth": {
            "fix google login": "https://www.drupal.org/files/issues/2019-03-07/3033444-37.patch"
          },

And it works!

I was having issues with creating accounts... but turns out my database was messed up from previous tests months ago and this solved the new user creation issue:

https://www.drupal.org/project/social_auth/issues/2914598#comment-13004018

My swiftmailer issue was unrelated and is now resolved.

I am still working to get require_login to work and that will be my focus this morning. I have been running require_auth and social_auth_google for many months with clients... so am looking forward to fixing this as it's the last issue before I can roll out all updates to production. And I don't know if the problem is related to social_auth at all... I'm guessing not.

wells’s picture

@m.lebedev & @eahonet, could you clarify what versions of Social Auth and Social Auth Google currently *do* work with Require Login? Is it this patch that causes issues or something else on the dev branch? If I get some time today I'll also try to do some testing with this, I'm just not familiar with the Require Login module.

gvso’s picture

The request is sent when I go to the auth path. The request is correct.
after that, redirection occurs to the destination.

Does this mean Social Auth works for you on PHP-FPM if require_login is not enabled?

eahonet’s picture

I am trying to get require_login:2.1 working with it.

Under /admin/config/people/require-login , I use these Path exclusions

/user/login/google/callback
/user/login/google/callback?state=*
/user/login/google
/user/login/google?destination=*
/user/login/google?destination=/
/user/login
/user/logout
/user/registration
/legal_accept
/user/reset*
/privacy-policy

I've also tried this patch: https://www.drupal.org/project/require_login/issues/3024495

I've tried looking more closely at /src/EventSubscriber/RequireLoginSubscriber.php (same area as targeted by patch above) and even just commenting out the return false that I thought was triggering it not to work... but still can't get past it.

-----

To better answer your question @wells, if I wanted to get a working version going of all these things, I run this command (I use the drupal composer project)

rm composer.lock; rm -Rf ./vendor/*; rm -Rf ./web/modules/contrib/*; composer require 'drupal/social_auth_google:2.x-dev#e3d47a3bab8eae2bc39b5167e9526135cd02f4e2' 'drupal/social_auth:2.x-dev#7ad52ff8eb621c5a7c4d4dbf0e8fb4c0070fbd60' 'drupal/social_api:2.x-dev#f92b77aa0cbffce13c16c7f7ffc56e4e47498b86'; drush cr

I then install require_login 1.12

With these patches:

"drupal/social_auth": {
            "fix stringtranlationtrait to userauthenticator": "https://www.drupal.org/files/issues/2018-11-10/3012823-4.patch"
},
"drupal/require_login": {
            "fixes redirect bug for pages guest cannot see": "https://www.drupal.org/files/issues/2018-11-07/2986046-18.patch"
},
gvso’s picture

@eahonet, Did Social Auth (and require_login) work for you before this patch or before beta 5?

eahonet’s picture

@gvso The only working require_login I've seen work was the older 1.12 with the older versions of social_auth 2.0-dev. require_login went through an overhaul recently and is now on 2.1.

I did make some progress and posted it here:
https://www.drupal.org/project/require_login/issues/3038652

It seems that when I go to /search... require_login says "no, you need to login first". Then when I try to login with social_auth_google, it starts the process, but ends up redirecting to /search before things finish... so no login finishes and then the user is taken back to the login page.

gvso’s picture

I don't think the error with require_login should be fixed here (not even that it should be fixed in Social Auth). Anyways, that issue should be handled separately, especially because this issue is about a major bug in Social Auth.

The only thing I'm concerned about is the compatibility with PHP FPM. I could run the authentication with destination successfully in my local server, but I would like to have input from @m.lebedev whether Social Auth works if require_login is disabled.

m.lebedev’s picture

Yes. social_auth works If require_login is disabled.

m.lebedev’s picture

Sorry. I checked one time again. When require_login is disabled:
1) social_auth 8.x-2.0-beta5 without patches
Auth works
2) social_auth 8.x-2.0-beta5 with patches.
Auth doesn't work

m.lebedev’s picture

StatusFileSize
new147.49 KB

Source: /core/lib/Drupal/Core/EventSubscriber/RedirectResponseSubscriber.php
There is a change of target url.

m.lebedev’s picture

StatusFileSize
new9.77 KB
new2.61 KB

Quick fix.

Upd: perhaps needing to create a static variable and after need to check if it exists in response filtering
Availability of oauth2state validation does not provide sufficient accuracy

gvso’s picture

That might work, but I wonder if we really need to go through all that "trouble" to solve it. Any thoughts?

eahonet’s picture

I do have an update. My path to social_auth_google + require_login + swiftmailer has made for a long week. I do have all of them fully working together now (we're testing this week with client). Some of the things I tried/thought were wrong. The final piece for me was removing the social_auth patch from this thread. My system had same/similar error... but it was something else... something older. I am running a more traditional LAMP stack with no nginx.

  1. Swiftmailer - my own stupidity in composer
  2. Require_login - changed how it handles the excluded paths. I did add a patch to ignore ?get parameters
  3. social_api - 2.0 beta5 - no patches
  4. social_auth - 2.0 beta5 - no patches needed... I did have to fix the database from a much older bug.
  5. social_auth_google - 2.0 beta4 - no patches needed

I wanted to at least update this thread and wish everyone luck. Also wanted to say thank you to those smarter than I that are working on these patches and these modules.

wells’s picture

@eahonet, could you clarify one thing — does applying one of the last few patches in this thread break your working setup or just have no effect on it?

eahonet’s picture

@wells - social_auth + require_login breaks with the #37 patch. It all started working when I removed the patch and rebuilt /vender and /modules/contrib. I'm not sure why or where... but it felt like something having to do with redirects. (https://www.drupal.org/project/require_login/issues/3038652)

wells’s picture

Thanks, @eahonet. I have just tested with the following and had success --

  1. Social API 8.x-2.0-beta5
  2. Social Auth 8.x-dev @2a79f3 w/#37 patch applied
  3. Social Auth GitHub 8.x-2.0-beta2
  4. Require login 8.x-2.1

Require login configured with the following path exclusions:

  • /user/login
  • /user/login/*

Social Auth with the GitHub provider works fine as long as no destination parameter is set, this is likely what you observed in your testing, @eahonet.

I also tested adding a /user/login/*?destination=* path exclusion, but it seems that parameters will not accept wildcards so that doesn't work as a workaround.

Regardless, I don't think this compatibility problem belongs in the scope of this particular issue. I think we should apply the patch in #37 and open a new issue to explore the Reqire login/destination problem, perhaps starting with @m.lebedev's research and a reroll of his patch. It looks more like this would be an issue for Require login, not Social Auth, but I'm not 100% sure about that.

m.lebedev’s picture

this would be an issue for Social Auth because I disabled require login last time

wells’s picture

Sorry, @m.lebedev, I missed that.

Since @gvso wasn’t able to reproduce with nginx+php-fpm, could you tell us more about your complete setup? Perhaps to include relevant nginx and php-fpm config?

You said you tested with a patched Social Auth 8.x-2.0-beta5. Could you also test with a patched 8.x-2.x-dev? And have you tested with a fresh D8 install with just Social Auth and it’s requiremnts?

I will try to review #53 later if I can get the time to build out the environment you having issues with.

eahonet’s picture

@wells

require_login + the patch from this https://www.drupal.org/project/social_auth/issues/3033444 will ignore any ? get parameters on exclusion paths. That's what I use. It still works to have

/user/login?destination=/search

redirect to /search after login (drupal login). But social_auth_google has a parameter of where to go and is set to just go to the homepage.

It's when I tried using the above patch (which I guess I don't need on my setup now) that logging in with Google via Social Auth breaks.... or works as long as require_login is uninstalled.

wells’s picture

@eahonet, I understand what you are saying and my test showed the same.

The important point that I got from my test, and why I don’t think this problem belongs with this issue, is that login with a patched Social Auth works and the reported errors are fixed regardless of whether or not Require login is installed (with proper exclusion configuration).

What doesn’t work is accessing login when a destination parameter is set. That, to me, signals an issue with Require login — it prevents us from accessing, e.g., /user/login/google?destination=/search, before even getting to a point where Social Auth would take action. But if you just go directly to /user/login/google authentication works fine.

m.lebedev’s picture

My configs:
Nginx
PHP-FPM

I checked the problem on the fresh drupal installation. I also checked last dev version of Social Auth.
The problem occurs if OAuth2ControllerBase doesn't run $response->send();

gvso’s picture

I think this issue has become very complex while the initial motivation was to avoid the warnings and errors. I propose the following

  1. Let's use the patch in #35. It doesn't produce any warnings/errors and still maintains the logic the current code has
  2. Let's solve @wells's concern about $response->send() in a different issue that might include something like the patch in #53
  3. In a different issue, we should check the compatibility problem with require_login

Does this sound good? Any suggestions?

wells’s picture

@gvso, my initial finding was that the sending instead of returning the response is preciscely what causes the RuntimeException warning. Did you test #35 with an nginx config and not get any errors? If so I think your plan makes sense.

Earlier I had enough time to get an nginx+php-fpm D8 going (thanks, @m.lebedev for providing your configs) but didn’t get around to an actual test. I should be able to do that within the next 8 or so hours if you didn’t get a chance to or want me to confirm.

wells’s picture

Ok, here is the setup I used --

Host

  • Ubuntu 18.04.2
  • Nginx 1.14.0
  • PHP v7.2.15
  • PHP-FPM

Drupal

  • Drupal 8.6.10
  • Social API 8.x-2.0-beta5
  • Social Auth 8.x-2.x dev@2a79f3
  • Social Auth Github 8.x-2.0-beta2

Test Results

No patches applied

Login successful - LogicException and RuntimeException logged.

#35 patch applied

Login failed - RuntimeException logged and error message, "Login failed. Invalid OAuth2 state. ".

#37 patch applied

Login successful - no exceptions logged.

#53 patch applied

Login successful - no exceptions logged.

Conclusions

After these tests, I still think #37 is the correct patch to address this issue and #35, in my test, doesn't even get me logged in. #57 seems like a lot of extra work to me and I don't think Social Auth should be stopping propagation of the KernelEvents::RESPONSE event for fear of causing issues with other contrib modules that act on that event (but I'm also not well versed in the events system on the whole).

I don't mean to ignore @m.lebedev's issue here, and since we got different results it may make sense for someone else to run similar tests, but I am fairly sure that $response->send() will always result in the RuntimeException error due to the fact the Drupal kernel is always handling the response.

Two additional notes re: my php-fpm setup, I used a socket as opposed to a local server and I only set the bare minimum FPM config (i.e. I excluded @m.lebedev's PHP config settings in the fpm pool config). The results could indicate some incompatibility issue with certain configurations of Nginx+PHP+PHP-FPM, but again I think that is not a topic for this issue (and I'd be happy to help investigate in another issue).

gvso’s picture

I still think #35 is the correct patch to address this issue and #37, in my test, doesn't even get me logged in.

Can you confirm you actually mean 35 and 37 in the correct order? The detail about what works and what doesn't seem to contradict this conclusion

wells’s picture

Shoot, sorry I mixed that up. I still recommend #37 over the rest. I’ll correct my comment above. Thanks.

m.lebedev’s picture

StatusFileSize
new572 bytes

It looks like my problem is not related to this module. I found an issue that describes what is happening.
I also created a module that reproduces the problem. After installing the module, go to "/drupal-test?destination=/" and there will be a redirect to the main page, but in fact there should be a redirect to google com.

I think we can close this issue and use patch #37.

Thanks.

UPD: I see that people solve this problem in their modules. For example.
We can do a similar solution.

// If destination parameter is set, save it.
$destination = $this->request->getCurrentRequest()->get('destination');
if ($destination) {
  $this->userAuthenticator->setDestination($destination);
  $this->request->getCurrentRequest()->query->remove('destination'); // <<--- THIS
}

It works for me. Auth works and redirect to destination works after auth.

wells’s picture

StatusFileSize
new7.69 KB
new1.2 KB

Thanks, for digging that up, @m.lebedev! Patch attached with your recommended change. Testing and working for me with Apache and nginx.

  • gvso committed aa296dc on 8.x-2.x authored by wells
    Issue #3033444 by gvso, wells, m.lebedev, ShaunDychko, eahonet, ndf:...
gvso’s picture

Status: Needs review » Fixed

Thank you everyone! I'll create new release later tonight

gvso’s picture

I created a new release. Hope everything works fine now. Thank you once more. We have to update the implementers now.

ndf’s picture

Thanks guys!

Status: Fixed » Closed (fixed)

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

itaran’s picture

had the similar problem with social_auth_twitter module, since TwitterAuthController doesn't extend OAuth2ControllerBase need separate patch to solve the problem https://www.drupal.org/files/issues/2020-08-12/3068326.patch, related issue https://www.drupal.org/project/social_auth_twitter/issues/3068326