2

I am trying to implement a google login onto my project. I already had a relatively working login scheme when I tried to use social_core's oauth with google to log in with a google account. It keeps throwing a social_core.exceptions.AuthMissingParameter error, meaning that somehow, the state isn't being passed at all.

I have been following the walkthrough done here https://fosstack.com/how-to-add-google-authentication-in-django/ as a baseline for how to implement this. When I run the code from this tutorial (besides some basic syntax and version errors), everything runs like a charm. However, when I try to implement it on my project, an error I cannot resolve occurs.

The url.py file I have, I have only imported some files and added the line

 path('auth/', include('social_django.urls', namespace='social')),

Other, than that, most of my test code is similar to the blog: like this in my common file.

 AUTHENTICATION_BACKENDS = (
   'social_core.backends.open_id.OpenIdAuth',  # for Google authentication
   'social_core.backends.google.GoogleOpenId',  # for Google authentication
   'social_core.backends.google.GoogleOAuth2',  # for Google authentication

   'django.contrib.auth.backends.ModelBackend',
  )

How the current situation is, is that I can click login, it takes me to a login page where I type in my google account, and then it throws the following exception:

Environment:


Request Method: GET
Request URL: http://localhost:3000/auth/complete/google-oauth2/

Django Version: 2.1.7
Python Version: 3.6.5
Installed Applications:
[##Some personal files###
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'markdownx',
 'social_django',
 'livereload']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'whitenoise.middleware.WhiteNoiseMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback:

File "C:\Users\Daniel\.virtualenvs\project-djMFGD5K\lib\site-packages\django\core\handlers\exception.py" in inner
  34.             response = get_response(request)

File "C:\Users\Daniel\.virtualenvs\project-djMFGD5K\lib\site-packages\django\core\handlers\base.py" in _get_response
  126.                 response = self.process_exception_by_middleware(e, request)

File "C:\Users\Daniel\.virtualenvs\project-djMFGD5K\lib\site-packages\django\core\handlers\base.py" in _get_response
  124.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "C:\Users\Daniel\.virtualenvs\project-djMFGD5K\lib\site-packages\django\views\decorators\cache.py" in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)

File "C:\Users\Daniel\.virtualenvs\project-djMFGD5K\lib\site-packages\django\views\decorators\csrf.py" in wrapped_view
  54.         return view_func(*args, **kwargs)

File "C:\Users\Daniel\.virtualenvs\project-djMFGD5K\lib\site-packages\social_django\utils.py" in wrapper
  49.             return func(request, backend, *args, **kwargs)

File "C:\Users\Daniel\.virtualenvs\project-djMFGD5K\lib\site-packages\social_django\views.py" in complete
  33.                        *args, **kwargs)

File "C:\Users\Daniel\.virtualenvs\project-djMFGD5K\lib\site-packages\social_core\actions.py" in do_complete
  43.         user = backend.complete(user=user, *args, **kwargs)

File "C:\Users\Daniel\.virtualenvs\project-djMFGD5K\lib\site-packages\social_core\backends\base.py" in complete
  40.         return self.auth_complete(*args, **kwargs)

File "C:\Users\Daniel\.virtualenvs\project-djMFGD5K\lib\site-packages\social_core\utils.py" in wrapper
  259.             return func(*args, **kwargs)

File "C:\Users\Daniel\.virtualenvs\project-djMFGD5K\lib\site-packages\social_core\backends\oauth.py" in auth_complete
  388.         state = self.validate_state()

File "C:\Users\Daniel\.virtualenvs\project-djMFGD5K\lib\site-packages\social_core\backends\oauth.py" in validate_state
  88.             raise AuthMissingParameter(self, 'state')

Exception Type: AuthMissingParameter at /auth/complete/google-oauth2/
Exception Value: Missing needed parameter state

Where I have edited out some of the more personal information, but those files aren't being used currently. I am pretty sure I have my keys done correctly, because the parameters are correct when I print them in the terminal after I run the server, and for the fact that google manages to send me the redirect at all.

Edit: Pretty sure the keys are correct, since when I remove them or type them incorrectly, I get a server not found error rather than a missing parameter error.

  • Did you make sure to add your Google Auth keys here: `SOCIAL_AUTH_GOOGLE_OAUTH2_KEY ='' #Paste CLient Key` `SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = '' #Paste Secret Key` – Hybrid Apr 07 '19 at 04:11
  • Yeah, I did do it, in my setting.py file at the bottom. When I run the server and print the value of those strings, it prints the correct values out. – dragon18456 Apr 07 '19 at 04:32

0 Answers0