Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django REST Framework and python-social-auth for registration/login user

I have to implement some REST api for mobile application.

I would to use Django REST framework.

The user (mobile side) can register an account only using Facebook, I would to use python-social-auth for this registration / login.

I'm new for this so I seen a lot of tutorial / documentations / example about it.

I have found only complete tutorial about Django + python_social_auth but I would to know exactly the best practice to make a user registration / login with REST-api.

Where can I found a complete example?

In my simple test I have also a problem: When I try to use this example:

@psa('social:complete')
def register_by_access_token(request, backend):
    # This view expects an access_token GET parameter, if it's needed,
    # request.backend and request.strategy will be loaded with the current
    # backend and strategy.
    token = request.GET.get('access_token')
    user = request.backend.do_auth(request.GET.get('access_token'))
    if user:
        login(request, user)
        return 'OK'
    else:
        return 'ERROR'

I obtain this error:

u'social' is not a registered namespace

I tried also to add this SOCIAL_AUTH_URL_NAMESPACE = 'myApp' in my settings but it not solve the problem.

like image 331
Safari Avatar asked Mar 10 '15 01:03

Safari


2 Answers

If it's not too late then why not use https://github.com/pennersr/django-allauth and https://github.com/Tivix/django-rest-auth which are designed to work together and simplify API based (social)login / logout / password reset token / password reset from token etc flows.

like image 178
xxx Avatar answered Oct 26 '22 14:10

xxx


I know that user has already selected an answer but since that answer directs us to another library, here's my answer, in case someone need it later:

"social" is the namespace you have to give to the urls provided by python-social-auth. You have to include a line as follows in to the urlpatterns list of your project's urls.py:

urlpatterns = [
    url(r'^social/', include('social.apps.django_app.urls', namespace="social")
    # All other remaining urls here.
]
like image 37
Rajeesh Punathil Avatar answered Oct 26 '22 12:10

Rajeesh Punathil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!