Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Login breaks when SESSION_COOKIE_SAMESITE is set to Strict #3232

Closed
100cube opened this issue Jan 12, 2023 · 5 comments
Closed

Google Login breaks when SESSION_COOKIE_SAMESITE is set to Strict #3232

100cube opened this issue Jan 12, 2023 · 5 comments

Comments

@100cube
Copy link

100cube commented Jan 12, 2023

Hi,

I have setup Google and Facebook social sign-in using all-auth using templates (i.e. not DRF, etc). Google login stopped working at some point. After a lot of digging, I have found that when ever I have the following setting

# in settings
SESSION_COOKIE_SAMESITE = 'Strict'

It fails most of the time, on production, with this setting on. The only account I have had success with is a Google Workspace account (non-gmail).

However, taking a hint from #2982, as soon as I remove that setting (it defaults to Lax) everything seems to work fine.

Facebook provider works fine with or without that setting, which leads to the question: is it possible to get the google provider to work similarly to the way the facebook provider works? It would be great for some sites to have SESSION_COOKIE_SAMESITE set to Strict

Many thanks

@derek-adair
Copy link

Could you provide logs please? always a good idea to provide a snapshot of what happened and any relevant configuration. This would include allauth version, python version, etc.

@andresmrm
Copy link

andresmrm commented Dec 7, 2023

I can confirm this error, but for me it happens every time when using SESSION_COOKIE_SAMESITE = 'Strict'.

Python 3.11.6
django-allauth 0.58.2 (also tested with 0.56.1)
Firefox 116 and Chromium 119

The error is raised here:
https://github.com/pennersr/django-allauth/blob/main/allauth/socialaccount/providers/oauth2/client.py#L93
Some relevant values there:

pkce_code_verifier == None
resp.json() == {'error': 'invalid_grant', 'error_description': 'Missing code verifier.'}

Related configs:

SOCIALACCOUNT_PROVIDERS = {
    'google': {
        'SCOPE': [
            'profile',
            'email',
        ],
        'AUTH_PARAMS': {
            'access_type': 'online',
        },
        'OAUTH_PKCE_ENABLED': True,
        'APP': {
            'client_id': '***',
            'secret': '***',
        },
    }
}

Not sure if related, but I've found this: simov/grant#199

Since pkce_code_verifier seems to come from the cookie ( https://github.com/pennersr/django-allauth/blob/main/allauth/socialaccount/providers/oauth2/views.py#L69 ), using Strict won't allow to access it when coming back from Google. Is there another way to store and access it?

I don't understand the details of the problem (if there is a solution or not), but I also would like to keep my session cookie as Strict.

@acuD1
Copy link

acuD1 commented Feb 6, 2024

Hi,

I encounter the same issue. Microsoft Graph is impacted as well.

settings.py:

# Cookie and Session
CSRF_COOKIE_SAMESITE = 'Strict'
CSRF_COOKIE_HTTPONLY = False
SESSION_COOKIE_SAMESITE = 'Strict'
SESSION_COOKIE_HTTPONLY = True

if IS_PROD_OR_PREPROD:
    CSRF_COOKIE_SECURE = True
    SESSION_COOKIE_SECURE = True

@pennersr
Copy link
Owner

Fixed via 40831dc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants