带有苹果 oauth 的 Django 社交发送没有 cookie 的最终重定向

Sha*_*ien 5 django cookies oauth django-socialauth apple-id

我们正在尝试使用 django-social 使 Apple oauth 为具有 django 后端的 Web 应用程序工作。初始登录请求设置了 sessionid cookie,但最终的 auth/complete 请求不会发送任何浏览器的 cookie。控制台中没有错误,我们的测试服务器使用 ssl。redirect_uri 是正确的,只是缺少 cookie。

我们尝试过的 Django 设置:

    SESSION_COOKIE_SECURE = False
    SESSION_COOKIE_SAMESITE = "Lax"
    SOCIAL_AUTH_APPLE_ID_CLIENT = '<our_website_name>'  # Your client_id com.application.your, aka "Service ID"
    SOCIAL_AUTH_APPLE_ID_TEAM = '<our_id>'  # Your Team ID, ie K2232113
    SOCIAL_AUTH_APPLE_ID_KEY = values.SecretValue()  # Your Key ID, ie Y2P99J3N81K
    SOCIAL_AUTH_APPLE_ID_SECRET_B64 = values.SecretValue()
    SOCIAL_AUTH_APPLE_ID_SCOPE = ['email', 'name']
    SOCIAL_AUTH_APPLE_ID_EMAIL_AS_USERNAME = True  # If you want to use email as username
    USE_X_FORWARDED_HOST = True
    SOCIAL_AUTH_REDIRECT_IS_HTTPS = True

    @property
    def SOCIAL_AUTH_APPLE_ID_SECRET(self):
        return base64.b64decode(self.SOCIAL_AUTH_APPLE_ID_SECRET_B64


    AUTHENTICATION_BACKENDS = (
        "rest_framework.authentication.TokenAuthentication",
        "social_core.backends.open_id.OpenIdAuth",  # for Google authentication
        "social_core.backends.google.GoogleOpenId",  # for Google authentication
        "social_core.backends.google.GoogleOAuth2",  # for Google authentication
        "django.contrib.auth.backends.ModelBackend",
        'social_core.backends.apple.AppleIdAuth', # Apple oauth
    )
Run Code Online (Sandbox Code Playgroud)

这会导致以下错误:

[04/May/2020 22:18:39] "GET /auth/login/apple-id/ HTTP/1.0" 302 0
Internal Server Error: /auth/complete/apple-id/
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python3.8/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/social_django/utils.py", line 49, in wrapper
    return func(request, backend, *args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/social_django/views.py", line 31, in complete
    return do_complete(request.backend, _do_login, user=request.user,
  File "/usr/local/lib/python3.8/site-packages/social_core/actions.py", line 45, in do_complete
    user = backend.complete(user=user, *args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/social_core/backends/base.py", line 40, in complete
    return self.auth_complete(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/social_core/utils.py", line 251, in wrapper
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/social_core/backends/oauth.py", line 388, in auth_complete
    state = self.validate_state()
  File "/usr/local/lib/python3.8/site-packages/social_core/backends/oauth.py", line 90, in validate_state
    raise AuthStateMissing(self, 'state')
social_core.exceptions.AuthStateMissing: Session value state missing.
[04/May/2020 22:18:53] "POST /auth/complete/apple-id/ HTTP/1.0" 500 102779
Run Code Online (Sandbox Code Playgroud)

这是我们错过的 django 设置还是 django-social 设置?任何人都可以帮助我们吗?谢谢!