Installation¶
- Install package:
pip install django-rest-auth
- Add
rest_auth
app to INSTALLED_APPS in your django settings.py:
INSTALLED_APPS = (
...,
'rest_framework',
'rest_framework.authtoken',
...,
'rest_auth'
)
Note
This project depends on django-rest-framework
library, so install it if you haven’t done yet. Make sure also you have installed rest_framework
and rest_framework.authtoken
apps
- Add rest_auth urls:
urlpatterns = patterns('',
...,
url(r'^rest-auth/', include('rest_auth.urls'))
)
You’re good to go now!
Registration (optional)¶
- If you want to enable standard registration process you will need to install
django-allauth
- see this doc for installation http://django-allauth.readthedocs.org/en/latest/installation.html. - Add
allauth
,allauth.account
andrest_auth.registration
apps to INSTALLED_APPS in your django settings.py:
INSTALLED_APPS = (
...,
'allauth',
'allauth.account',
'rest_auth.registration',
)
- Add rest_auth.registration urls:
urlpatterns = patterns('',
...,
(r'^rest-auth/', include('rest_auth.urls')),
(r'^rest-auth/registration/', include('rest_auth.registration.urls'))
)
Social Authentication (optional)¶
Using
django-allauth
,django-rest-auth
provides helpful class for creating social media authentication view. Below is an example with Facebook authentication.Note
Points 1, 2 and 3 are related with
django-allauth
configuration, so if you have already configured social authentication, then please go to step 4. Seedjango-allauth
documentation for more details.allauth.socialaccount
andallauth.socialaccount.providers.facebook
apps to INSTALLED_APPS in your django settings.py:rest_auth.registration.views.SocialLoginView
withFacebookOAuth2Adapter
adapter as an attribute:Note
Starting from v0.21.0, django-allauth has dropped support for context processors. Check out http://django-allauth.readthedocs.org/en/latest/changelog.html#from-0-21-0 for more details.