How might I go about adding a Google+ API sign-in to my Django website?
相关问题
- Django __str__ returned non-string (type NoneType)
- Django & Amazon SES SMTP. Cannot send email
- Django check user group permissions
- Django restrict pages to certain users
- UnicodeEncodeError with attach_file on EmailMessag
相关文章
- Profiling Django with PyCharm
- How to embed Google Speech to Text API in Python p
- Why doesn't Django enforce my unique_together
- MultiValueDictKeyError in Django admin
- Does google-hosted jquery helps google to track vi
- Django/Heroku: FATAL: too many connections for rol
- Is there a google API to read cached content? [clo
- Django is sooo slow? errno 32 broken pipe? dcramer
@rhaps0dy's answer is correct, but
python-social-auth
is now deprecated and migrated associal-auth-app-django
. So this is what I made different from @rhaps0dy guidelines.python-social-auth
, I installedsocial-auth-app-django
,'social.apps.django_app.default'
becomes'social_django'
'social.backends.google.GoogleOAuth2'
is now'social_core.backends.google.GoogleOAuth2'
url("^soc/", include("social.apps.django_app.urls", namespace="social"))
becomesurl("^soc/", include("social_django.urls", namespace="social"))
First you must create OAuth credentials for Google+.
Now let's add
python-social-auth
to your Django app.python-social-auth
withpip
Set the appropriate Django settings:
'social.apps.django_app.default'
toINSTALLED_APPS
:SOCIAL_AUTH_GOOGLE_OAUTH2_KEY
andSOCIAL_AUTH_GOOGLE_OAUTH2_SECRET
settings with the client key and secret you created earlier. The client key is the "Client ID" listed in the "Credentials" screen in the Google developer console, the one which ends in ".apps.googleusercontent.com". Only take the part before the dot. The secret is listed as "Client secret".Make sure you have the
AUTHENTICATION_BACKENDS
setting explicitly defined, and that it contains'social.backends.google.GoogleOAuth2'
. An example would be:Define the
SOCIAL_AUTH_PIPELINE
setting as detailed in the python-social-auth documentation. What every setting does is listed in that page.If you have something to do with the information you get from Google+, I recommend defining a function:
where
user
is adjango.contrib.auth.models.User
object, andresponse
is a dictionary. Then add that function to theSOCIAL_AUTH_PIPELINE
using the full module path, aftercreate_user
.If you don't want to do anything with that information you can leave the default pipeline as-is.
Finally, you'll want to add the
python-social-auth
urls to your site'surlpatterns
:And that should do it! It's time for testing. First,
./manage.py makemigrations
for the required migrations ofpython-social-auth
, and then./manage.py migrate
, as explained here. Then, you can run the development server, and go to http://localhost:8000/soc/login/google-oauth2/?next=/ .Hopefully I did not skip explaining any step and it will work. Feel free to ask more questions and read the docs. Also, here is a working example that you should check out.