Anuj Gupta
Anuj Gupta

Reputation: 1

Apple social login using django rest auth

I have configured my apple developer account accordingly.

View Code:

from dj_rest_auth.registration.views import SocialLoginView as DJSocialLoginView
from allauth.socialaccount.providers.apple.client import AppleOAuth2Client
from allauth.socialaccount.providers.apple.views import AppleOAuth2Adapter

class CustomAppleLoginView(DJSocialLoginView):
    adapter_class = AppleOAuth2Adapter
    callback_url = f'{domain}/api/v1/user/accounts/apple/login/callback'
    client_class = AppleOAuth2Client

    def post(self, request, *args, **kwargs):
        try:
            return super().post(request, *args, **kwargs)
        except Exception as e:
            # Handle the OAuth2Error here
            error_message = str(e)
            return Response({"error": error_message}, status=status.HTTP_400_BAD_REQUEST)

settings:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'rest_framework',
    'rest_framework.authtoken',
    'django_filters',
    'drf_yasg',

    'django.contrib.gis',
    'ckeditor',

    # local apps
    'user',
    'core',
    'api',
    'webapi',
    'rental',
    'marketplace',
    'kora',

    # 3rd party
    'dj_rest_auth',
    'dj_rest_auth.registration',
    'corsheaders',

    'import_export',
    'rangefilter',
    'django_q',


    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'allauth.socialaccount.providers.facebook',
    'allauth.socialaccount.providers.google',
    'allauth.socialaccount.providers.apple',

    'fcm_django',
    'celery',
    'django_celery_beat',
    'django_celery_results',
]

SOCIALACCOUNT_PROVIDERS = {
    # IOS login credentials
    "apple": {
        "APP": {
            # Your service identifier.
            "client_id": os.environ.get('APPLE_CLIENT_ID'),

            # The Key ID (visible in the "View Key Details" page).
            "secret": os.environ.get('APPLE_SECRET'),

             # 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": os.environ.get('APPLE_KEY'),

            # The certificate you downloaded when generating the key.
            "certificate_key": os.environ.get('APPLE_CERTIFICATE_KEY')
        }
    }
}

domain/api/v1/user/accounts/apple/login/?process=login

error pic

Also:

On passing access_token, id_token to the above view

I am getting:

{ "error": "Invalid id_token" }

I followed the steps from:

Getting error "invalid_request: Invalid web redirect url" when using Apple ID sign-in with Firebase

but still got same issue

Upvotes: 0

Views: 67

Answers (0)

Related Questions