Search code examples
djangofacebookdjango-rest-frameworkdjango-allauthpython-social-auth

Can I login in with Facebook as an unregistered user? (Django, all-auth)


I'm building my Django RESTful Framework to retrieve and post data for Mobile. I'm using djang-rest-auth (which is just all-auth with RESTful functionality; more info: http://django-rest-auth.readthedocs.io/en/latest/).

Question: Social Auth in all-auth is not clear to me. Can you finish this use case?

Use Case: Unregistered User

  1. User Login with Facebook on Mobile
  2. Mobile gets facebook token from Facebook SDK
  3. Mobile sends token to our DRF Backend server URL which is '/rest-auth/facebook'
  4. And what happens? Can you complete this Use Case? <- This is my question

My guesses:

  • all-auth automatically create new user for facebook user token and return new token?
  • Then, it saves created user to settings.AUTH_USER_MODEL? Or...?
  • I found 'social account' in Django admin. Are we saving User in this account..?

Solution

  • Yes, you are correct. After receiving facebook token Django will create SocialAccount instance which include backend name (facebook in your case) and facebook id of user. This instance will be related with AUTH_USER_MODEL by ForeignKey so when next time user will try to login Django will find SocialAccount by specified facebook id and return related AUTH_USER_MODEL instance.