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

Google login failure - TypeError: string indices must be integers: Upgrade from 0.51.0 -> 0.52.0 #3228

Closed
henningbra opened this issue Jan 1, 2023 · 3 comments

Comments

@henningbra
Copy link

First of all. Thanks for a great library as it takes away the pain of Auth. We are using it in a Nature Reservation project and it saves and improves the life of both Elephants and humans in South-east Asia.

Back to topic. When bumping version from 0.51.0 to 0.52.0 project failed to login Google users. Returning to 0.51.0 the login works.

I'm not 100% sure the problem resides in this project, but djangorestframework and dj-rest-auth had unchanged versions.

Trying my best to give the right information. Sentry reported this errors multiple times:

TypeError: string indices must be integers
File "django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "django/core/handlers/base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "contextlib.py", line 75, in inner
return func(*args, **kwds)
File "django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "django/views/generic/base.py", line 70, in view
return self.dispatch(request, *args, **kwargs)
File "django/utils/decorators.py", line 43, in _wrapper
return bound_method(*args, **kwargs)
File "django/views/decorators/debug.py", line 89, in sensitive_post_parameters_wrapper
return view(request, *args, **kwargs)
File "dj_rest_auth/views.py", line 53, in dispatch
return super().dispatch(*args, **kwargs)
File "rest_framework/views.py", line 509, in dispatch
response = self.handle_exception(exc)
File "rest_framework/views.py", line 469, in handle_exception
self.raise_uncaught_exception(exc)
File "rest_framework/views.py", line 480, in raise_uncaught_exception
raise exc
File "rest_framework/views.py", line 506, in dispatch
response = handler(request, *args, **kwargs)
File "dj_rest_auth/views.py", line 130, in post
self.serializer.is_valid(raise_exception=True)
File "rest_framework/serializers.py", line 227, in is_valid
self._validated_data = self.run_validation(self.initial_data)
File "rest_framework/serializers.py", line 429, in run_validation
value = self.validate(value)
File "dj_rest_auth/registration/serializers.py", line 150, in validate
login = self.get_social_login(adapter, app, social_token, token)
File "dj_rest_auth/registration/serializers.py", line 60, in get_social_login
social_login = adapter.complete_login(request, app, token, response=response)
File "allauth/socialaccount/providers/google/views.py", line 22, in complete_login
response["id_token"],

@pennersr
Copy link
Owner

pennersr commented Jan 2, 2023

Thanks, that's really nice to hear -- the first paragraph that is. As for this issue, I believe that is something to be sorted out in dj-rest-auth. I am not really familiar with their code base, but from a first glance it seems that they are making this call in their serializers.py:

            login = self.get_social_login(adapter, app, social_token, token)

...whereas allauth expects this signature:

    def complete_login(self, request, app, token, response, **kwargs):

The issue is the token parameter -- the original response (dict) is expected here. I previous versions of allauth this parameter was not used for Google, hence, this mismatch did not cause an issue.

@wanglophile
Copy link

@henningbra What version of djangorestframework and dj-rest-auth are you using?

@henningbra
Copy link
Author

@wanglophile

Combination of below created a problem:
django-allauth==0.52.0 # https://github.com/pennersr/django-allauth
djangorestframework==3.14.0 # https://github.com/encode/django-rest-framework
dj-rest-auth==2.2.5 # https://github.com/jazzband/dj-rest-auth

Fixed by reverting to combination:
django-allauth==0.51.0 # https://github.com/pennersr/django-allauth
djangorestframework==3.14.0 # https://github.com/encode/django-rest-framework
dj-rest-auth==2.2.5 # https://github.com/jazzband/dj-rest-auth

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

3 participants