Login failed. Invalid OAuth2 state.

Created on 28 July 2023, about 1 year ago
Updated 11 March 2024, 6 months ago

Problem/Motivation

Google auth callback tips "Login failed. Invalid OAuth2 state."

Steps to reproduce

Configuration is ok.

Proposed resolution

Who can help me to solved this problem. Please help me to do this emergency.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Needs work

Version

4.0

Component

Code

Created by

πŸ‡¨πŸ‡³China Lychee555

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

Comments & Activities

  • Issue created by @Lychee555
  • πŸ‡ΊπŸ‡ΈUnited States cbwiedel

    I am having the same problem. social_auth + social_auth_google are on 4.0

  • πŸ‡ΊπŸ‡ΈUnited States youknowww

    Think I've figured out part of this. After user login, Drupal now calls the exact same redirect request using another query parameter check_logged_in=1.

    The state error triggers because the check_logged_in request leaves out the state. I also think it expects a NULL response? But this was such a debugging rabbit hole I'm too tired to care at the moment.

    I believe this can only be fixed in the main Social Auth module. I haven't seen the issue reported there. Came across this open issue while building my own Social Auth module for ArcGIS by copying Facebook's. Installed Google and reproduced the same results as described in this open issue which makes me think this problem is for all Social Auth modules, currently.

    Slapped together a little patch for the main Social Auth module which solves the problem. New here but my boss at work says you guys call this "killing kittens".

    In Social Auth: src/Controller/OAuth2ControllerBase.php at line 290

          // Drupal checks callback requests to see if a user is logged in
          $checkLogin = $this->request->getCurrentRequest()->query->get('check_logged_in');
    
          // If this is Drupal's check logged in request, ignore and exit fn
          if($checkLogin == '1'){
            return NULL;
          }
    

    If you're curious about what's going on with the check_logged_in stuff, I found it in:
    https://api.drupal.org/api/drupal/core%21modules%21user%21src%21Authentication%21Provider%21Cookie.php/function/Cookie%3A%3AaddCheckToUrl
    and
    https://api.drupal.org/api/drupal/core%21modules%21user%21user.module/function/user_login_finalize

  • πŸ‡ΊπŸ‡ΈUnited States NickTech

    I can confirm this error started after our recent update from Drupal 9 to 10 running Social Auth 4.1.0. Downgrading to Social Auth 3.1.0 fixed Google logins for now.

  • Issue was unassigned.
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    We're getting

    Error 400: redirect_uri_mismatch

    is that the same issue?

    Fixing version.

Production build 0.71.5 2024