Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does allauth work when user logs in via social registration

I have been trying to use django-allauth to provide Social registration, but I am having trouble configuring the profiles for the user. There is no documentation of django-allauth which tells

  1. how a django user account is created when a user logs in via a third party such as facebook
  2. What username is assigned to that user and what password is used.
  3. Certain third party providers such as Facebook provide a lot of information about the user such as their name, email etc. so how can we get them and save in the user account/profile

If anybody has used allauth in their projects and can provide some details then it would be really helpful.

like image 384
Sachin Avatar asked Dec 12 '11 21:12

Sachin


1 Answers

I am using django_allauth in my project.

(1) How a django user account is created when a user logs in via a third party such as facebook ?

You should take a look at :

  1. your admin panel and see what happens when somebody logs in.
  2. allauth.facebook.views.login and try to track the login process

It is something like this (in a few words):

  1. When a user logs in your site via his Facebook credentials he is given an access token
  2. This token is saved in the FACEBOOK_ACCESS_TOKENS table (you can see it in the admin panel)
  3. With this access token and with the help of Facebook GraphApi we know his social_id
  4. When we know his social_id - we can have his Facebook account from our database
  5. If we haven't saved it in the db already - we save the Facebook account in the FACEBOOK_ACCOUNTS table (Facebook Accounts in the admin panel)
  6. Then we create a user in the USERS table with the data present in the Facebook account. (you can see the new user in the Users section in the admin panel)


(2) What username is assigned to that user and what password is used ?

As I mentioned before with the help of Facebook GraphApi we get the username of the Facebook user and it is assigned to the User profile as User.username


(3) Certain third party providers such as Facebook provide a lot of information about the user such as their name, email etc. so how can we get them and save in the user account/profile?

Again - the Facebook GraphApi - it gets you the info you need.

I have integrated django_allauth in my site and it is working properly. I will be happy to answer(if I can) if you have more questions.


EDIT - For the avatar support...

I think you have to take a look at the django_allauth settings and particularly in:

SOCIALACCOUNT_AVATAR_SUPPORT (= 'avatar' in settings.INSTALLED_APPS)

Enable support for django-avatar. When enabled, the profile image of the user is copied locally into django-avatar at signup.

like image 119
forbdn Avatar answered Oct 31 '22 19:10

forbdn