django-allauth Google 登录不工作 iOS

django-allauth Google login not working on iOS

我正在用 django 构建一个 PWA,但 django-allauth Google 登录有这个问题。在装有 Chrome 和 Edge 的 Windows PC 上一切正常。但是当尝试在 iOS 设备上使用 Google 登录时,我得到社交网络登录失败代码:'unknown',异常:'PermissionDenied()'

任何想法可能是什么原因或在哪里搜索它?

编辑

我尝试进行更多调试并遇到这些错误(仅在 iOS 设备上!):

Internal Server Error: /accounts/google/login/callback/ Traceback (most recent call last): File "/home/kava/.virtualenvs/django3/lib/python3.8/site-packages/allauth/socialaccount/providers/oauth2/views.py", line 141, in dispatch login.state = SocialLogin.verify_and_unstash_state( File "/home/kava/.virtualenvs/django3/lib/python3.8/site-packages/allauth/socialaccount/models.py", line 325, in verify_and_unstash_state raise PermissionDenied() django.core.exceptions.PermissionDenied

我设法解决了问题。

错误是由此函数中 if "socialaccount_state" not in request.session: 后面的行引起的:

@classmethod
def verify_and_unstash_state(cls, request, verifier):
    if "socialaccount_state" not in request.session:
        raise PermissionDenied()
    state, verifier2 = request.session.pop("socialaccount_state")
    if verifier != verifier2:
        raise PermissionDenied()
    return state

所以问题出在会话数据上,更准确地说,'socialaccount_state' 丢失了。

谷歌搜索这个与 iOS 相关的问题后,我发现了 this 个话题。

我按照那里的建议将 SESSION COOKIE_SAMESITE and CSRF_COOKIE_SAMESITE 更改为 None,它起作用了!

顺便说一句,如果 'None' 在撇号之间,则它在 iOS 12 台设备上不起作用。