我已经在django实现了Apple登录,并使用了allauth和rest。我的实现方式和Google登录一样,它运行得很好。
views.py
class AppleLogin(SocialLoginView):
adapter_class = AppleOAuth2Adapterurls.py
urlpatterns = [
path("auth/apple/", AppleLogin.as_view(), name="apple-login"),
]pip版本
Django==2.2.17
django-allauth==0.43.0
django-rest-auth==0.9.3
djangorestframework==3.8.2
djangorestframework-jwt==1.11.0当我按照下面的方式进行测试时,我得到了KeyError: 'id_token',这就是错误的来源:https://github.com/pennersr/django-allauth/blob/master/allauth/socialaccount/providers/apple/views.py#L92
我不知道如何纠正这个错误。
谢谢你的帮助!
curl -X POST 'https://.../auth/apple/' \
-d 'access_token=AUTHENTICATION_CODE'
or
curl -X POST 'https://.../auth/apple/' \
-d 'id_token=ID_TOKEN' \
-d 'access_token=AUTHENTICATION_CODE'发布于 2021-01-04 16:30:20
使用此自定义serializerClass。https://github.com/pennersr/django-allauth/pull/2424#issuecomment-651913243
问题似乎在django-rest-auth中,您的身份验证视图应该如下所示
from allauth.socialaccount.providers.apple.views import AppleOAuth2Adapter
from allauth.socialaccount.providers.apple.client import AppleOAuth2Client
from rest_auth.registration.views import SocialLoginView
class AppleLogin(SocialLoginView):
adapter_class = AppleOAuth2Adapter
callback_url = 'https://anycallbackurlhere'
client_class = AppleOAuth2Client
serializer_class = CustomAppleSocialLoginSerializerSerializerClass中唯一的更改是在validate函数中,因此您只需重写该方法。
from rest_auth.registration.serializers import SocialLoginSerializer
class CustomAppleSocialLoginSerializer(SocialLoginSerializer):
def validate(self, attrs):
.... #copy the method from the link abovehttps://stackoverflow.com/questions/64850805
复制相似问题