[英]Apple login in django rest framework with allauth and rest-auth
I have implemented Apple login in django with allauth and rest-auth.我已经在 django 中使用 allauth 和 rest-auth 实现了 Apple 登录。 I implemented same way as Google login which worked perfectly.
我实现了与谷歌登录相同的方式,效果很好。
views.py视图.py
class AppleLogin(SocialLoginView):
adapter_class = AppleOAuth2Adapter
urls.py网址.py
urlpatterns = [
path("auth/apple/", AppleLogin.as_view(), name="apple-login"),
]
pip versions点子版本
Django==2.2.17
django-allauth==0.43.0
django-rest-auth==0.9.3
djangorestframework==3.8.2
djangorestframework-jwt==1.11.0
When I test as below I'm getting KeyError: 'id_token'
and this is where error comes from: https://github.com/pennersr/django-allauth/blob/master/allauth/socialaccount/providers/apple/views.py#L92当我如下测试时,我收到
KeyError: 'id_token'
这就是错误的来源: https : //github.com/pennersr/django-allauth/blob/master/allauth/socialaccount/providers/apple/views。 py#L92
I have no idea how to fix this error.我不知道如何解决这个错误。
Thank you for your help !感谢您的帮助 !
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'
Use this custom serializerClass.使用此自定义序列化器类。 https://github.com/pennersr/django-allauth/pull/2424#issuecomment-651913243
https://github.com/pennersr/django-allauth/pull/2424#issuecomment-651913243
It seems that the problem is in django-rest-auth Your authentication view should look like this似乎问题出在 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 = CustomAppleSocialLoginSerializer
The only change in the SerializerClass is in the validate
function so you can just override that method SerializerClass 中唯一的变化是在
validate
函数中,因此您可以覆盖该方法
from rest_auth.registration.serializers import SocialLoginSerializer
class CustomAppleSocialLoginSerializer(SocialLoginSerializer):
def validate(self, attrs):
.... #copy the method from the link above
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.