24

I'm using Django Social Auth for connect with Facebook issue and it works perfect. I have developed an API for my Django app with Django Rest Framework. But I'm confused about using Django Social Auth with Django Rest Framework for iOS devices.

I have searched 1, 2, 3 and 4 but they are generally with Angular.js. I'm not familiar with iOS development.

  • What is different between facebook connect with spa and a mobile device? * How could I use these packages together?
  • May I migrate from django-social-auth to python-social-auth?
halfer
  • 18,701
  • 13
  • 79
  • 158
TheNone
  • 5,078
  • 10
  • 46
  • 95
  • 3
    [This](http://psa.matiasaguirre.net/docs/use_cases.html#signup-by-oauth-access-token) is the common pattern when implementing auth on APIs with python-social-auth. A similar approach can be implemented with django-social-auth. – omab Apr 03 '14 at 05:38
  • possible duplicate of [oauth2 token authentication using django-oauth-toolkit and python-social-auth](http://stackoverflow.com/questions/27051209/oauth2-token-authentication-using-django-oauth-toolkit-and-python-social-auth) – Kevin Brown Aug 24 '15 at 21:39

3 Answers3

18

You can now authenticate your users against your django-rest-framework with bearer tokens/third party access tokens from any python-social-auth backend (Facebook, Google, Github, etc.) using this library https://github.com/PhilipGarnero/django-rest-framework-social-oauth2

This module provides a python-social-auth and oauth2 support for django-rest-framework. Thus this saves you a lot of time to setup what is required to have your DRF with social authorization and to be OAuth2 secure.

Hugo Sequeira
  • 474
  • 4
  • 10
  • 1
    How does Django-rest-framework-social-oauth2 compare to the DRF recommended Django OAuth Toolkit? https://www.django-rest-framework.org/api-guide/authentication/#django-oauth-toolkit – Harry Moreno Jan 09 '19 at 00:35
11

I think that you can achieve that using django rest framework, django-rest-auth and allauth. Those three work nice together.

  • With django rest framework you already familiar.
  • The allauth is responsible for the social authentication.
  • The django-rest-auth responsible for create the RESTful api for the social authentication, i.e. the connection between django-rest-framework and allauth.
Kevin Brown
  • 36,829
  • 37
  • 188
  • 225
Daniel Mishne
  • 144
  • 1
  • 5
  • 2
    None of the solution available has a proper documentation. eg django all oauth, django-restauth – XciA Nov 20 '17 at 11:12
  • 3
    Agree with @XciA, the docs especially for django-rest-auth are so minimal it's very difficult to understand how to do social auth. – Evan Zamir Jan 29 '18 at 22:21
5

It is recommended that you let python-social-auth handle the Facebook login for you, and instead you use another OAuth plugin for Django REST Framework to authenticate with Django. This has the added benefit of also supporting non-Facebook login through the standard Django authentication system.

I'm confused about using Django Social Auth with Django Rest Framework for ios devices.

I recently answered a similar question about implementing authentication with python-social-auth and Django REST Framework. It includes some important points to read about when implementing authentication using a third party along with some important notes about how you should not pass the third-party OAuth tokens back to your client.

How could I use these packages together?

While that answer specifically mentions using OAuth as the authentication method for the API that is behind python-social-auth, you can use other authentication methods that internally use Django authentication system, such as TokenAuthentication. In any case, you will end up proxying authentication between your front end application and your third party authentication provider, using your back end API.

What is different between facebook connect with spa and a mobile device?

Facebook provides direct integration with some mobile operating systems, most notably iOS and Android. This bypasses your API for authentication, and directly authenticates your mobile application with Facebook. Ideally, it would be authenticating your back end API instead of the mobile application. This may still be possible to do if you pass the access token back to your API manually, essentially doing the same thing that python-social-auth would be doing, but that could be risky and may not be worth the extra effort.

Facebook Connect (now known as just Facebook Login) works in a similar way to how Facebook integration works on mobile devices. The one difference that may work in your favor is that it's very easy to move from Facebook Login for single page apps, to an OAuth-based authentication pattern. This is documented in the Facebook developers documentation as "Manually Building a Login Flow" and is compatible with libraries that support OAuth-based login, like python-social-auth.

May I migrate from django-social-auth to python-social-auth?

This shouldn't be an issue anymore, as python-social-auth has effectively replaced django-social-auth.

Community
  • 1
  • 1
Kevin Brown
  • 36,829
  • 37
  • 188
  • 225