Skip to main content

django sauth is an easy to setup social authentication/registration mechanism with support for several auth providers.

Project description

SAUTH - Social Media Authentication Component

Overview

Sauth Provide the social media authentication and authorization for django applications.

Dependencies

OAuth 2.0 support depends on python-oauth2
Twiiter support depends on Twython
The backends(social media provider) demands the application registration on their corresponding website.
Facebook
Linkedin
google
Twitter

Dependency Package Installation

pip install twython or easy_install twython
pip install oauth2

Installation

from pypi

pip install django-sauth or easy_install django-sauth

from github , clone the project django-sauth

https://github.com/renjith-tring/django-sauth


Configuration

integrate sauth with django based applications

settings.py

Install sauth in python path(virtualenv) and add the package in to installed apps

INSTALLED_APPS = ( ‘.................’,
'sauth',
)
Sauth providing two approach
Collect all the data from the provider and display into json format and you can easily process the data in to your needs , it will be good approach for Rest Api applications.
No need syncdb or migrate
Collect the data from the provider , store into the database and make sure user into Authenticated with the system.
Need syncdb or migrate(depend on django version)

Following second approach Add SauthAuthBackend in AUTHENTICATION_BACKENDS in settings.py

AUTHENTICATION_BACKENDS = (
'sauth.backends.sauthcommonbackend.SauthAuthBackend',
'django.contrib.auth.backends.ModelBackend',)
Add The SauthExceptionMiddleware in MIDDLEWARE_CLASSES

MIDDLEWARE_CLASSES = (
'sauth.middleware.middleware.SauthExceptionMiddleware',
)
Urls.py

urlpatterns = patterns('',
…………………………………..,
url(r'^', include('sauth.urls')),
……………………………………,
)


Authentication with Facebook

Create the application in facebook developer account[ https://developers.facebook.com/quickstarts/?platform=web]

Add App id and Secrect key in settings.py

FACEBOOK_API_KEY = '*********************'
FACEBOOK_SECRET_KEY = '*****************************************'
FACEBOOK_APP_ID = FACEBOOK_API_KEY
SAUTH_REDIRECT_URL = 'http://localhost:8000/complete/'
[ Testing redirect url for google and linkedin is ‘http://127.0.0.1:8000/complete/’ ,
for production for all the provider please add the redirect url like this[ eg: www.example.com/complete / ]
SAUTH_FACEBOOK_SCOPE = [ ] # your choice, list format [ ‘scope1’,’scope2..’]
[ default : ['user_about_me','public_profile','email'] ]

SAUTH_FACEBOOK_EXTRA_FIELDS = [ ] #your choice , list format
[‘field1’,’field2’,..]
[ default : ['id','first_name','last_name','email','gender'] ]



optional [ second approach ]
============
SAUTH_AFTER_AUTH_URL = '/login/complete'
SAUTH_CREATE_AUTH_USER = True
==========================================

SAUTH_LOGIN_ERROR_URL = 'sautherror' [ url name ]
[ default error will be shown by json format , if you need to get the errors in your views function you can add the url name here , you can easily get the error from session
status : request.session['error_status']
description : request.session['error_desc']
reason : request.session['error_reason']
]

Authentication with Linkedin
Create the Application in linkedin developer account[
https://www.linkedin.com/developer/apps/new?csrfToken=ajax%3A2134433661926155952 ]

LINKEDIN_CLIENT_ID = '**************************'
LINKEDIN_SECRET_KEY = '******************************'
SAUTH_LINKEDIN_SCOPE = [ ] #your choice list format
[ default:['rw_company_admin','r_basicprofile','w_share','r_emailaddress'] ]
SAUTH_LINKEDIN_EXTRA_FIELDS = ( ‘l-filed1’ ,...,) # your choice in tuple format
[ default : (id,skills,first-name,last-name,positions:(company:(name)),formatted-name,date-of-birth,industry,email-address,location,headline,picture-urls::(original)) ]




Authentication with Twitter

Create the application with twitter developer account [ https://apps.twitter.com/app/new ]

TWITTER_KEY = “ ”
TWITTER_SECRET = “ ”

Authentication with Google account

Create the application with google developer account :
[ https://console.developers.google.com/projectselector/apis/library ]

GOOGLE_KEY = “******************.apps.googleusercontent.com”
GOOGLE_SECRET_KEY = “ ************************* ”
SAUTH_GOOGLE_SCOPE = [ ‘scope1’,’..2’, ] # your choice in list field

[ default : ['plus.login', 'plus.me', 'userinfo.email', 'userinfo.profile'] ]


How to Use .
=============

backends
=========

1) facebook
2) twitter
3) google
4) linkedin-oauth2

Authorization url is :
=========================

htpp://127.0.0.1:8000/auth/<backend>

Project details


Release history Release notifications | RSS feed

This version

1

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page