To allow users login with google account in our django can be easily done by using django-allauth package.
this package can be installed by:
pip install django-allauth
configurations have illustrated this very clear in the official docs, just do as this page does:
now we need to go to google developer console,
in the left sidebar, find APIs & Services:
click on the Credentials option and we would comt to the Credential page:
at the top of this page, we could click to create a Credential:
three forms to be filled:
save, done. A Client ID and Client secret will be generated for us automatically.
In our database, django-allauth created several tables for us with prefix
socialaccount_, we need to modify two of them:
id: leave it empty, this would be generated by our database (this id will be used in
client_id: the client_id google generated for us in APIs & Services
secret：the client_secret google generated for us in APIs & Services
key: we leave it empty
|1 (if it is the fisrt one)||1|
id:leave it empty, this would be generated by our database
pk/idnumber generated in socialaccount_socialapp table
site_id: 1 (usually)
now all the configurations are done, you access your login page (generated by django-allauth), there would be a google option for login with google account. And if you have configured your Email sender in your project, you will be able to login (sign up) successfully.
Bellow is an example of how to insert records into
[user@localhost]$ mysql -u root -p Enter password: mysql> use DATABASENAME; # repalce "DATABASENAME" with your database name Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> insert into socialaccount_socialapp values (1, 'Google', 'Google', 'YOUR_CLIENT_ID', 'YOUR_CLENT_SECRET', ''); Query OK, 1 row affected (0.01 sec) mysql> mysql> insert into socialaccount_socialapp_sites values (1, 1, 1); Query OK, 1 row affected (0.01 sec) mysql> exit Bye