Django oauth setup implementation (login with google and apple)

im having issues with django auath social authenticationd

# settings.py
[
    "allauth",
    "allauth.account",
    "dj_rest_auth",
    "dj_rest_auth.registration",
    "allauth.socialaccount",
    "allauth.socialaccount.providers.google",
    "allauth.socialaccount.providers.apple",
]

# views.py
class GoogleLogin(SocialLoginView):
    adapter_class = GoogleOAuth2Adapter
    callback_url = "http://localhost:3000/"
    client_class = OAuth2Client

urls.py
 path("google/", GoogleLogin.as_view(), name="google_login"),

# sample request
{
  "access_token": "string",
  "code": "string",
  "id_token": "string"
}

i get 500 response
File “/Users/teddy/effectstudio/cloopp/venv/lib/python3.11/site-packages/allauth/socialaccount/providers/google/views.py”, line 22, in complete_login
response[“id_token”],
~~~~~~~~^^^^^^^^^^^^
TypeError: string indices must be integers, not ‘str’

any idea on how to resolve this.

It looks like response is a string and not a dictionary as expected. What is response actually set to? It may also be helpful to share the full traceback of the error. I suspect there’s some other issue within integration and it’s presenting as this particular error.

Internal Server Error: /api/auth/google/v2/
Traceback (most recent call last):
  File "/Users/teddy/effectstudio/cloopp/venv/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/teddy/effectstudio/cloopp/venv/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/teddy/.pyenv/versions/3.11.2/lib/python3.11/contextlib.py", line 81, in inner
    return func(*args, **kwds)
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/teddy/effectstudio/cloopp/venv/lib/python3.11/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/teddy/effectstudio/cloopp/venv/lib/python3.11/site-packages/django/views/generic/base.py", line 103, in view
    return self.dispatch(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/teddy/effectstudio/cloopp/venv/lib/python3.11/site-packages/django/utils/decorators.py", line 46, in _wrapper
    return bound_method(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/teddy/effectstudio/cloopp/venv/lib/python3.11/site-packages/django/views/decorators/debug.py", line 92, in sensitive_post_parameters_wrapper
    return view(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/teddy/effectstudio/cloopp/venv/lib/python3.11/site-packages/dj_rest_auth/views.py", line 48, in dispatch
    return super().dispatch(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/teddy/effectstudio/cloopp/venv/lib/python3.11/site-packages/rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/teddy/effectstudio/cloopp/venv/lib/python3.11/site-packages/rest_framework/views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/Users/teddy/effectstudio/cloopp/venv/lib/python3.11/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
    raise exc
  File "/Users/teddy/effectstudio/cloopp/venv/lib/python3.11/site-packages/rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/teddy/effectstudio/cloopp/venv/lib/python3.11/site-packages/dj_rest_auth/views.py", line 125, in post
    self.serializer.is_valid(raise_exception=True)
  File "/Users/teddy/effectstudio/cloopp/venv/lib/python3.11/site-packages/rest_framework/serializers.py", line 227, in is_valid
    self._validated_data = self.run_validation(self.initial_data)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/teddy/effectstudio/cloopp/venv/lib/python3.11/site-packages/rest_framework/serializers.py", line 429, in run_validation
    value = self.validate(value)
            ^^^^^^^^^^^^^^^^^^^^
  File "/Users/teddy/effectstudio/cloopp/venv/lib/python3.11/site-packages/dj_rest_auth/registration/serializers.py", line 159, in validate
    login = self.get_social_login(adapter, app, social_token, token)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/teddy/effectstudio/cloopp/venv/lib/python3.11/site-packages/dj_rest_auth/registration/serializers.py", line 61, in get_social_login
    social_login = adapter.complete_login(request, app, token, response=response)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/teddy/effectstudio/cloopp/venv/lib/python3.11/site-packages/allauth/socialaccount/providers/google/views.py", line 22, in complete_login
    response["id_token"],
    ~~~~~~~~^^^^^^^^^^^^
TypeError: string indices must be integers, not 'str'
Internal Server Error: /api/auth/google/v2/
Traceback (most recent call last):
  File "/Users/teddy/effectstudio/cloopp/venv/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/teddy/effectstudio/cloopp/venv/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/teddy/.pyenv/versions/3.11.2/lib/python3.11/contextlib.py", line 81, in inner
    return func(*args, **kwds)
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/teddy/effectstudio/cloopp/venv/lib/python3.11/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/teddy/effectstudio/cloopp/venv/lib/python3.11/site-packages/django/views/generic/base.py", line 103, in view
    return self.dispatch(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/teddy/effectstudio/cloopp/venv/lib/python3.11/site-packages/django/utils/decorators.py", line 46, in _wrapper
    return bound_method(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/teddy/effectstudio/cloopp/venv/lib/python3.11/site-packages/django/views/decorators/debug.py", line 92, in sensitive_post_parameters_wrapper
    return view(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/teddy/effectstudio/cloopp/venv/lib/python3.11/site-packages/dj_rest_auth/views.py", line 48, in dispatch
    return super().dispatch(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/teddy/effectstudio/cloopp/venv/lib/python3.11/site-packages/rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/teddy/effectstudio/cloopp/venv/lib/python3.11/site-packages/rest_framework/views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/Users/teddy/effectstudio/cloopp/venv/lib/python3.11/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
    raise exc
  File "/Users/teddy/effectstudio/cloopp/venv/lib/python3.11/site-packages/rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/teddy/effectstudio/cloopp/venv/lib/python3.11/site-packages/dj_rest_auth/views.py", line 125, in post
    self.serializer.is_valid(raise_exception=True)
  File "/Users/teddy/effectstudio/cloopp/venv/lib/python3.11/site-packages/rest_framework/serializers.py", line 227, in is_valid
    self._validated_data = self.run_validation(self.initial_data)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/teddy/effectstudio/cloopp/venv/lib/python3.11/site-packages/rest_framework/serializers.py", line 429, in run_validation
    value = self.validate(value)
            ^^^^^^^^^^^^^^^^^^^^
  File "/Users/teddy/effectstudio/cloopp/venv/lib/python3.11/site-packages/dj_rest_auth/registration/serializers.py", line 159, in validate
    login = self.get_social_login(adapter, app, social_token, token)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/teddy/effectstudio/cloopp/venv/lib/python3.11/site-packages/dj_rest_auth/registration/serializers.py", line 61, in get_social_login
    social_login = adapter.complete_login(request, app, token, response=response)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/teddy/effectstudio/cloopp/venv/lib/python3.11/site-packages/allauth/socialaccount/providers/google/views.py", line 22, in complete_login
    response["id_token"],
    ~~~~~~~~^^^^^^^^^^^^
TypeError: string indices must be integers, not 'str'
[01/Sep/2023 21:55:21] "POST /api/auth/google/v2/ HTTP/1.1" 500 153362

this the full stack trace error
i hope this helpful

Have you determined what response actually is?

Thank you. I have been able to resolve. I install these version of the packages below.
django-allauth==0.50.0
dj-rest-auth==4.0.1