0

我可以使用电子邮件和密码成功登录,但是当我尝试将社交身份验证与 django allauth、django-rest-knox 和 dj rest auth 结合使用时,在尝试生成令牌时出现以下错误:


raise type(exc)(msg)
AttributeError: Got AttributeError when attempting to get a value for field `token` on serializer `KnoxSerializer`.
The serializer field might be named incorrectly and not match any attribute or key on the `tuple` instance.
Original exception text was: 'tuple' object has no attribute 'token'.

这是我的意见.py

from allauth.socialaccount.providers.facebook.views import FacebookOAuth2Adapter
from allauth.socialaccount.providers.google.views import GoogleOAuth2Adapter
from dj_rest_auth.registration.views import SocialLoginView

class FacebookLogin(SocialLoginView):
    adapter_class = FacebookOAuth2Adapter


class GoogleLogin(SocialLoginView):
    adapter_class = GoogleOAuth2Adapter
    client_class = OAuth2Client

网址.py

from users.views import  FacebookLogin, GoogleLogin

    path('social-rest-auth/login/facebook/',
         FacebookLogin.as_view(), name='fb_login'),
    path('social-rest-auth/login/google/',
         GoogleLogin.as_view(), name='google_login'),

序列化程序.py


class KnoxSerializer(serializers.Serializer):
    """
    Serializer for Knox authentication.
    """
    token = serializers.CharField()
    user = UserSerializer(many=False, read_only=True)
settings.py

REST_AUTH_SERIALIZERS = {
    'USER_DETAILS_SERIALIZER': 'users.serializers.UserSerializer',
    'TOKEN_SERIALIZER': 'users.serializers.KnoxSerializer',
    'PASSWORD_RESET_SERIALIZER': 'users.serializers.PasswordResetSerializer'
}
REST_FRAMEWORK = {
    # 'DEFAULT_PERMISSION_CLASSES': (
    #     'rest_framework.permissions.IsAuthenticated',
    # ),
    'EXCEPTION_HANDLER': 'users.exceptions.custom_exception_handler',
    'DEFAULT_AUTHENTICATION_CLASSES': (
        # 'rest_framework.authentication.BasicAuthentication',
        'rest_framework.authentication.SessionAuthentication',
        # 'rest_framework.authentication.TokenAuthentication',
        'knox.auth.TokenAuthentication',
    )
}

请问有人可以帮我吗?

4

0 回答 0