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.