New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sign In with Apple KeyError: 'id_token' #201
Comments
You have to submit CODE only, not access_token (and not access_token AND code). |
@fialkovod Thanks for your help on this. When I submit only the
Do you believe that this is an error with the swift code that I am using to submit it? I had found this online and seems to be what people have luck with. It takes the authorizationCode from the response and sends it to dj-rest-auth as I really appreciate it! |
It sounds like this is a client error so I'm going to close this. Let me know if I'm mistaken. |
After a few day's of looking into this, it's actually an issue with the SocialLoginSerializer from dj-rest-auth. Here is the custom serializer, changes and steps that needed to be used. What are your thoughts on adding a serializer to dj-rest-auth exclusively for Apple's version of OAuth? I can help with a PR if this is a route to consider. Edit: The linked Stack Overflow question was also updated with the same information today. |
Sounds good. I'll re-open this ticket now. |
In our project, I used def get_access_token_data(self, request, app, client):
""" We need to gather the info from the apple specific login """
add_apple_session(request)
# Exchange `code`
code = get_request_param(request, "code")
access_token_data = client.get_access_token(code)
return {
**access_token_data,
**self.get_user_scope_data(request),
"id_token": request.apple_login_session.get("id_token"),
} You can see, before getting def add_apple_session(request):
"""
Fetch an apple login session
"""
if not hasattr(request, "apple_login_session"):
session_key = request.COOKIES.get(APPLE_SESSION_COOKIE_NAME)
request.apple_login_session = SessionStore(session_key) It can be seen that if we use the RESTful API, we may not bring the class AppleLoginView(SocialLoginView):
adapter_class = AppleOAuth2Adapter
callback_url = 'https://yourdomain/accounts/apple/login/callback/'
client_class = AppleOAuth2Client
class AppleConnectView(SocialConnectView):
adapter_class = AppleOAuth2Adapter
callback_url = 'https://yourdomain/accounts/apple/login/callback/'
client_class = AppleOAuth2Client
apple_login_view = AppleLoginView.as_view()
apple_connect_view = AppleConnectView.as_view() Hope it can be helpful. |
@LanceMoe I think your solution is much easier and more effective than the one listed in allauth (that I followed and posted about). I tested your PR and it works really well and keeps it to the one serializer. Thank you for doing that. |
Closing this as the PR has been merged. |
I recommend documenting this support. It took a while to find this superior looking solution after stumbling with django-allauth |
can you send the StackOverflow link. |
I want to start off by saying fantastic job on this package.
An issue was raised on StackOverflow last week about Sign In with Apple and rest-auth here that is not seeing much traffic.
This issue seems to be the same with dj-rest-framework.
Following the example, this is what I got:
Submitting the access_token and code, you get the same
KeyError: 'id_token'
(targeting the same line) that is mentioned in the Stack Overflow question.When using Django allauth exclusively, Sign In with Apple works. It's only over the API requests that it does not.
Thanks for the help.
The text was updated successfully, but these errors were encountered: