Django Social login/register using rest framework

617 Views Asked by At

I am using DRF as rest framework and want to use the social login for user signup and login. For now, I am using angular to signup with Google which is successful and got following response:

"id":"105372307735.........",
"name":"XYZ",
"email":"[email protected]",
"photoUrl":"https://lh4.googleusercontent.com/-C..............",
"authToken":"ya29.Glx2.....................",
"provider":"GOOGLE"

How could I use same response to register user and login in django rest framework?

Thanks

1

There are 1 best solutions below

0
On

I know it's too late but this might help someone who is struggling with social logins hence posting it here. use this module django-rest-framework-social-oauth2, follow the instructions that are there on their official Github, they have examples for Facebook and Google.

Also, add these pipelines to your settings

SOCIAL_AUTH_PIPELINE = (
  'social_core.pipeline.social_auth.social_details',
  'social_core.pipeline.social_auth.social_uid',
  'social_core.pipeline.social_auth.auth_allowed',
  'social_core.pipeline.social_auth.social_user',
  'social_core.pipeline.user.get_username',
  'social_core.pipeline.social_auth.associate_by_email',
  'social_core.pipeline.user.create_user',
  'social_core.pipeline.social_auth.associate_user',
  'social_core.pipeline.social_auth.load_extra_data',
  'social_core.pipeline.user.user_details',
)

This will allow users to authenticate themselves with multiple social logins for a single user account.

Run

python manage.py makemigrations

and

python manage.py migrate

if you've followed the instructions properly from their official GitHub, then you should be able to visit localhost:8000/auth/convert-token from where you can convert your tokens to your app tokens and use it to authenticate users.