First, go to https://console.cloud.google.com/apis/ and create a project.



Click on it and choose web application, and add these two URLs,
http://127.0.0.1:8000 for Authorized JavaScript origins
http://127.0.0.1:8000/accounts/google/login/callback/ for Authorized redirect URIs


Now run the server using python manage.py runserver and open admin. Go to this page http://127.0.0.1:8000/admin/sites/site/1/change/ and make these changes,
Provider: Google
Name: OAuth App
Client id: [YOUR GOOGLE AUTH CLIENT ID]
Secret key: [YOUR GOOGLE AUTH CLIENT SECRET]
Sites: 127.0.0.1:8000
Then, click on Social Applications click Add and fill in the details as follows

Now logout yourself because you logged in as a superuser and open http://127.0.0.1:8000/accounts/login/ and you can see Google login option.

If you have customized django-allauth templates then you can directly use this code in your template.
{% load socialaccount %}
<h1>Google Login</h1>
<a href="{% provider_login_url 'google'%}?next=/">Login with Google</a>
Last updated