Skip to content
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

AppleIdAuth not working #241

Open
DataGreed opened this issue Mar 4, 2021 · 6 comments
Open

AppleIdAuth not working #241

DataGreed opened this issue Mar 4, 2021 · 6 comments

Comments

@DataGreed
Copy link

I've been trying to implement sign in with apple following this article and instructions from the docs, but still struggling.

I have set up everything from the docs, but whenever I make a request to convert_token view, I always end up with the following Exception:

#...

File "/myproject/.venv/lib/python3.8/site-packages/rest_framework/views.py" in dispatch
  502.             response = handler(request, *args, **kwargs)

File "/myproject/.venv/lib/python3.8/site-packages/rest_framework_social_oauth2/views.py" in post
  70.         url, headers, body, status = self.create_token_response(request._request)

File "/myproject/.venv/lib/python3.8/site-packages/oauth2_provider/views/mixins.py" in create_token_response
  128.         return core.create_token_response(request)

File "/myproject/.venv/lib/python3.8/site-packages/oauth2_provider/oauth2_backends.py" in create_token_response
  145.         headers, body, status = self.server.create_token_response(

File "/myproject/.venv/lib/python3.8/site-packages/oauthlib/oauth2/rfc6749/endpoints/base.py" in wrapper
  116.             return f(endpoint, uri, *args, **kwargs)

File "/myproject/.venv/lib/python3.8/site-packages/rest_framework_social_oauth2/oauth2_endpoints.py" in create_token_response
  59.         return grant_type_handler.create_token_response(

File "/myproject/.venv/lib/python3.8/site-packages/oauthlib/oauth2/rfc6749/grant_types/refresh_token.py" in create_token_response
  60.             self.validate_token_request(request)

File "/myproject/.venv/lib/python3.8/site-packages/rest_framework_social_oauth2/oauth2_grants.py" in validate_token_request
  94.             user = backend.do_auth(access_token=request.token)

File "/myproject/.venv/lib/python3.8/site-packages/social_core/utils.py" in wrapper
  248.             return func(*args, **kwargs)

File "/myproject/.venv/lib/python3.8/site-packages/social_core/backends/oauth.py" in do_auth
  403.         return self.strategy.authenticate(*args, **kwargs)

File "/myproject/.venv/lib/python3.8/site-packages/social_django/strategy.py" in authenticate
  107.         return authenticate(*args, **kwargs)

File "/myproject/.venv/lib/python3.8/site-packages/django/contrib/auth/__init__.py" in authenticate
  73.             user = backend.authenticate(request, **credentials)

File "/myproject/.venv/lib/python3.8/site-packages/social_core/backends/base.py" in authenticate
  80.         return self.pipeline(pipeline, *args, **kwargs)

File "/myproject/.venv/lib/python3.8/site-packages/social_core/backends/base.py" in pipeline
  83.         out = self.run_pipeline(pipeline, pipeline_index, *args, **kwargs)

File "/myproject/.venv/lib/python3.8/site-packages/social_core/backends/base.py" in run_pipeline
  113.             result = func(*args, **out) or {}

File "/myproject/.venv/lib/python3.8/site-packages/social_core/pipeline/social_auth.py" in social_details
  5.     return {'details': dict(backend.get_user_details(response), **details)}

File "/myproject/.venv/lib/python3.8/site-packages/social_core/backends/base.py" in get_user_details
  173.         raise NotImplementedError('Implement in subclass')

Exception Type: NotImplementedError at /web/hook/apple-sign-in/
Exception Value: Implement in subclass

It's weird - it seems like the BaseAuth tries to authenticate the user instead of AppleIdAuth, but my settings seem to be correct in this regard.

In my settings.py:

AUTHENTICATION_BACKENDS = [
    'rest_framework_social_oauth2.backends.DjangoOAuth2',      
    'django.contrib.auth.backends.ModelBackend'
]
SOCIAL_AUTH_AUTHENTICATION_BACKENDS = (
    'social_core.backends.apple.AppleIdAuth',   
)
REST_FRAMEWORK = {
   # ...
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework.authentication.SessionAuthentication',
        'rest_framework.authentication.TokenAuthentication',

        'oauth2_provider.contrib.rest_framework.OAuth2Authentication',          
        'rest_framework_social_oauth2.authentication.SocialAuthentication',    
    ),
    
}

Example payload I am trying to send to convert_token:

{
         "grant_type": "convert_token",
         "client_id": "~someid",
         "client_secret": "~someappsecret",
         "backend": "apple-id",
         "token": "~sometokenfromapple",
        }

Am I missing something? Please advise.

@DataGreed
Copy link
Author

Or should I add social_core.backends.apple.AppleIdAuth to AUTHENTICATION_BACKENDS? What is SOCIAL_AUTH_AUTHENTICATION_BACKENDS is used for?

@wagnerdelima
Copy link

This lib is not maintained anymore. Use https://github.com/wagnerdelima/drf-social-oauth2 instead

@AbdullahEslah
Copy link

try to send :
identity token from iOS app here it worked with me :
{
"grant_type": "convert_token",
"client_id": "~someid",
"client_secret": "~someappsecret",
"backend": "apple-id",
"token": "identity token", <--
}

@denizdogan
Copy link

@AbdullahEslah Oh my God, thanks a lot! I have been struggling with this for two days and now I found your solution!

@AbdullahEslah
Copy link

@denizdogan

@AbdullahEslah Oh my God, thanks a lot! I have been struggling with this for two days and now I found your solution!

Any Time friend i was like you 9 months ago ..
we all here to help each other 😃

@rajanazirul
Copy link

Hi, need help to implement apple auth, i try to follow step from @AbdullahEslah but receive error like this.
{ "error": "invalid_request", "error_description": "Invalid backend parameter." }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants