Question in short: Login with DRF, python-social-auth and Angularjs works with Facebook but not Google.
I'm building a django app that needs to enable users to signup/login via Facebook and Google in addition to locally stored email/password combo. It works as follows:
access_token
is collected via FB or Google's API.access_token
is sent to the server by an AJAX request.do_auth
function for authentication.facebook
, this works fine. When, it's Google
(Tried both google-oauth2
and google-plus
), do_auth
eventually raises a 403 Forbidden error. When the related url, https://googleapis.com/plus/v1/people/me?access_token=ACCESS_TOKEN&alt=json is copied to the browser, it shows an error message:Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup
http://localhost:5001
to javascript origin field and http://localhost:5001/social/complete
to redirect uri field (Latter field is filled up later. Same result with or without it.)settings.SOCIAL_AUTH_GOOGLE_OAUTH2_KEY
and settings.SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET
. Double checked their accuracy.'social.backends.google.GoogleOAuth2'
to settings.AUTHENTICATION_BACKENDS. Tried placing here both GoogleOAuth2 and GooglePlus together and separately.settings.SOCIAL_AUTH_USE_DEPRECATED_API
as True. This also fails but the error is now 401.What to do next to get this working with Google authentication too? Gone through many other similar questions here and issues reported in Github.
Here's the relevant code:
class SignUpView(CreateAPIView):
def create(self, request, *args, **kwargs):
provider = request.data['provider']
strategy = load_strategy(request)
backend = load_backend(strategy=strategy, name=provider, redirect_uri=None)
token = request.data['access_token']
try:
user = backend.do_auth(token, user=None, **data)
except AuthAlreadyAssociated:
pass
I've recently struggled with similar problem, but my situation was a little bit different because I'm using django-rest-framework-social-oauth2.
First of all I've noticed you enabled Google+ API, but:
Added 'social.backends.google.GoogleOAuth2' to settings.AUTHENTICATION_BACKENDS.
Try change your settings to (this is described in python social auth docs) :
AUTHENTICATION_BACKENDS = (
...
'social_core.backends.google.GooglePlusAuth',
)
SOCIAL_AUTH_GOOGLE_PLUS_KEY = '...'
SOCIAL_AUTH_GOOGLE_PLUS_SECRET = '...'
Another thing that can be useful for you is google oauth playground
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With