Configure Apple login in Django rest framework with Allauth and rest-auth

1.3k Views Asked by At

I'm using Django + Django Rest Framework for a project for RESTful services to a mobile APPs. Now I have to integrate Apple-login.

For social-login I already using Allauth + Allauth Socialaccount + rest-auth for Facebook login.

As reported into Allauth documentation, it seams that supports Apple also.

Reading the documentation I read that It's necessary to configure it (into Django settings) using something like this:

    SOCIALACCOUNT_PROVIDERS = {
    "apple": {
        "APP": {
            # Your service identifier.
            "client_id": "your.service.id",

            # The Key ID (visible in the "View Key Details" page).
            "secret": "KEYID",

             # Member ID/App ID Prefix -- you can find it below your name
             # at the top right corner of the page, or it’s your App ID
             # Prefix in your App ID.
            "key": "MEMAPPIDPREFIX",

            # The certificate you downloaded when generating the key.
            "certificate_key": """-----BEGIN PRIVATE KEY-----
s3cr3ts3cr3ts3cr3ts3cr3ts3cr3ts3cr3ts3cr3ts3cr3ts3cr3ts3cr3ts3cr
3ts3cr3ts3cr3ts3cr3ts3cr3ts3cr3ts3cr3ts3cr3ts3cr3ts3cr3ts3cr3ts3
c3ts3cr3t
-----END PRIVATE KEY-----
"""
        }
    }
}

I'm trying to make a first test using the already described libraries:

I added my url:

url(r'^api/v1/users/applelogin', AppleLoginAPIView.as_view(), name='applelogin-user-url'),

I created my view:

class AppleLoginAPIView(SocialLoginView):
    adapter_class = AppleOAuth2Adapter
    callback_url = 'https://www.example.com'
    client_class = AppleOAuth2Client

Trying this first test I have some errors and I discovered that It's necessary to create (into the DB .. using for example the Django-admin a Social-App selecting Apple as selected provider.

Are the requested Django settings (as reported above) necessary?

What's the purpose of the callback_url?

0

There are 0 best solutions below