I want to log in using python-social-auth function to log in to Google Plus in Django. When I log in from my site, everything works fine, and the correct data is added to the database.
However, I want to authenticate from my Android app as well. The user logs in to the application, which then sends the access token to the django API, which processes the login process to the following code, adapted from the documentation :
@csrf_exempt @serengeti_api_request @psa('social:complete') def login_social_token(request, backend): # Ensure the token has been specified. token = request.META.get('HTTP_ACCESSTOKEN') if token is None: raise SerengetiApiRequestException('Access token is missing!') # Login the user for this session user = request.backend.do_auth(token) if user is None: raise SerengetiApiRequestException('Could not authenticate user!') login(request, user) # Store the email address if one has been specified (eg Twitter) email = request.META.get('HTTP_EMAIL') if email is not None: user.email = email user.save() # Prepare the parameters to be returned response = dict({ 'id': user.id, 'first_name': user.first_name, 'last_name': user.last_name, 'api_key': request.session.session_key, }) # Return a 200 status code to signal success. return HttpResponse(json.dumps(response, indent=4), status=200)
When you log in from the website, the social_auth_usersocialauth table contains:
id | provider | uid | extra_data ========================================== 10 | google-oauth2 | <myemail> | {"token_type": "Bearer", "access_token": "<token>", "expires": 3600}
However, when you log out of the application using the above function, the operation completes normally, but the table entry looks like this:
id | provider | uid | extra_data ========================================= 10 | google-oauth2 | <empty> | {"access_token": "", "expires": null}
In addition, the auth_user table contains username as eeed494412obfuscated48bc47dd9b instead of the Google Plus username, and the email field is empty.
What am I doing wrong and how can I get the same functionality as on the website?
I would like to mention that I implemented Facebook and Twitter authentication from an Android application that call the above function and save the correct data, only problems with Google Plus create problems.