0

I am trying Google Oauth2 key,id using django-social-auth to setup a google+ login to my website. I included 2 function defs in views.py, one for index and other profile. So the login is attempted in index and if there is a pass it HttpResponseRedirects to profile page. I am stuck at this point where the login dialog for google+ pops up, i enter the user credentials and it is accepted. However, the index is not redirecting to profile page. In the code below if you see, the request.user.is_authenticated() is always returning false. On printing the request.user i always get AnonymousUser. Please let me know if i am doing anything wrong here or i need to add something to the code. My views.py currently looks like this.

def index(request):
    #print request.user

    if request.user.is_authenticated():
        print "user is authenticated"
        return HttpResponseRedirect('/profile')

    return render_to_response('index.html', {}, context_instance=RequestContext(request))

def profile(request):
    return render_to_response('profile.html')

The settings file has the following parameters related :

GOOGLE_OAUTH2_CLIENT_ID = <client-id>
GOOGLE_OAUTH2_CLIENT_SECRET = <secret-key>
GOOGLE_OAUTH2_USE_UNIQUE_USER_ID = True

LOGIN_URL          = '/'
LOGIN_REDIRECT_URL = '/profile/'
LOGIN_ERROR_URL    = '/login-error/'

AUTHENTICATION_BACKENDS = (
'social_auth.backends.google.GoogleOAuthBackend',
'social_auth.backends.google.GoogleOAuth2Backend',
'social_auth.backends.google.GoogleBackend',
'social_auth.backends.OpenIDBackend',
'django.contrib.auth.backends.ModelBackend',
)

I followed this google developer's page in doing this task.

I tried the link w.r.t RequestContext solution and a solution mentioned in similar problem, but both weren't fruitful.

  • I think you are mixing things you dont need to (i may be wrong). Did you set your authentication backends??? http://django-social-auth.readthedocs.org/en/latest/configuration.html – cdvv7788 Feb 20 '15 at 17:35
  • Wow that was quick! :) yes i have added them. Please check the updated code above for settings.py. – bharathkallurs Feb 20 '15 at 17:38
  • Think i am mixing up the javascript redirecting the user after login to the same page with, the django code! I shall check this and update accordingly :) meanwhile, still looking for any suggestions! – bharathkallurs Feb 20 '15 at 17:46
  • Checking around, it seems django-social-auth is deprecated and you should use http://python-social-auth.readthedocs.org/en/latest/index.html instead. Also, that process with the button is not required if you are going to use a social login library, as they abstract that process away. Just check your settings and use something like this in your template to get started: https://github.com/omab/python-social-auth/blob/master/examples/django_example/example/templates/home.html – cdvv7788 Feb 20 '15 at 18:51
  • Even i got to know that django-social-auth is deprecated. I too found this link for google+ login http://psa.matiasaguirre.net/docs/backends/google.html#google-sign-in. Thanks for your efforts! :) will check python-social-auth and see how it goes. Your link seems to give an elucidated example. thanks again! – bharathkallurs Feb 20 '15 at 19:02

0 Answers0