django-socialregistration

django-socialregistration enables developers to add user registration with OAuth, OAuth2 and OpenID services.

See documentation for installation and configuration.

|image0|

Setup

Requirements

Note

The v0.5.x versions of django-socialregistration require at least Django v1.3.2 due to the use of class based views. For previous versions of Django please use django-socialregistration v0.4.x.

Installation

pip install django-socialregistration
pip install -e git+https://github.com/pythonforfacebook/facebook-sdk#egg=FacebookSDK

Configuration

The most basic configuration is to add socialregistration and django.contrib.sites to your INSTALLED_APPS

INSTALLED_APPS = (
'django.contrib.sites',
'socialregistration'
)

Note

To make sure that your redirects and callbacks work properly you’ll have to set the domain in the Sites app to the correct value.

If you find yourself redirected to example.com, check your Sites configuration through the Django admin interface.

Include socialregistration.urls into your root urls.py file

urlpatterns = patterns('',
# Here be other urls ...
        url(r'^social/', include('socialregistration.urls',
                namespace = 'socialregistration')))

Note

The namespace = 'socialregistration' argument is required.

Include django.core.context_processors.request in your TEMPLATE_CONTEXT_PROCESSORS in your settings file

TEMPLATE_CONTEXT_PROESSORS = (
'django.core.context_processors.request',
)

Note

When your views render templates that include social registration tags (such as {% twitter_button %}) they will need to pass the RequestContext in as a parameter

return render_to_response('template.html', c, context_instance=RequestContext(request))

Note on sessions

When starting the registration process, all the user’s temporary data is stored in the user’s session. If you’re developing on http://127.0.0.1:8000, you will have to set your callback URLs to begin with http://127.0.0.1:8000 too or you will get a new session when returning to the site and socialregistration won’t be able to find the temporary data and subsequently throw a KeyError.

Also not that Twitter for example will not accept http://localhost:8000 as a valid domain for the callback URL so you’ll have to use http://127.0.0.1:8000 when developing your site.

Services

Facebook

  • Add socialregistration.contrib.facebook to your INSTALLED_APPS
INSTALLED_APPS = (
        'socialregistration',
        'socialregistration.contrib.facebook'
)
  • Add socialregistration.contrib.facebook.auth.FacebookAuth to your AUTHENTICATION_BACKENDS
AUTHENTICATION_BACKENDS = (
        'django.contrib.auth.backends.ModelBackend',
        'socialregistration.contrib.facebook.auth.FacebookAuth',
)
  • Add your API keys and (comma seperated) permissions you request:
FACEBOOK_APP_ID = ''
FACEBOOK_SECRET_KEY = ''
FACEBOOK_REQUEST_PERMISSIONS = ''
  • Anywhere in your templates:
{% load facebook %}
{% facebook_button %}

Or:

{% load facebook %}
{% facebook_button 'custom/button/image.png' %}

Foursquare

  • Add socialregistration.contrib.foursquare to your INSTALLED_APPS
INSTALLED_APPS = (
        'socialregistration',
        'socialregistration.contrib.foursquare'
)
  • Add socialregistration.contrib.foursquare.auth.FoursquareAuth to your AUTHENTICATION_BACKENDS
AUTHENTICATION_BACKENDS = (
        'django.contrib.auth.backends.ModelBackend',
        'socialregistration.contrib.foursquare.auth.FoursquareAuth',
)
  • Add your API keys and (comma seperated) permissions you request:
FOURSQUARE_CLIENT_ID = ''
FOURSQUARE_CLIENT_SECRET = ''
FOURSQUARE_REQUEST_PERMISSIONS = ''
  • Anywhere in your templates:
{% load foursquare %}
{% foursquare_button %}

Or:

{% load foursquare %}
{% foursquare_button 'custom/button/image.png' %}

Github

  • Add socialregistration.contrib.github to your INSTALLED_APPS
INSTALLED_APPS = (
        'socialregistration',
        'socialregistration.contrib.github'
)
  • Add socialregistration.contrib.github.auth.GithubAuth to your AUTHENTICATION_BACKENDS
AUTHENTICATION_BACKENDS = (
        'django.contrib.auth.backends.ModelBackend',
        'socialregistration.contrib.github.auth.GithubAuth',
)
  • Add your API keys and (comma seperated) permissions you request:
GITHUB_CLIENT_ID = ''
GITHUB_CLIENT_SECRET = ''
GITHUB_REQUEST_PERMISSIONS = ''
  • Anywhere in your templates:
{% load github %}
{% github_button %}

Or:

{% load github %}
{% github_button 'custom/button/image.png' %}

LinkedIn

  • Add socialregistration.contrib.linkedin to your INSTALLED_APPS
INSTALLED_APPS = (
        'socialregistration',
        'socialregistration.contrib.linkedin'
)
  • Add socialregistration.contrib.linkedin.auth.LinkedInAuth to your AUTHENTICATION_BACKENDS
AUTHENTICATION_BACKENDS = (
        'django.contrib.auth.backends.ModelBackend',
        'socialregistration.contrib.linkedin.auth.LinkedInAuth',
)
  • Add your API keys:
LINKEDIN_CONSUMER_KEY = ''
LINKEDIN_CONSUMER_SECRET_KEY = ''
  • Anywhere in your templates:
{% load linkedin %}
{% linkedin_button %}

Or:

{% load linkedin %}
{% linkedin_button 'custom/button/image.png' %}

OpenID

  • Add socialregistration.contrib.openid to your INSTALLED_APPS
INSTALLED_APPS = (
        'socialregistration',
        'socialregistration.contrib.openid'
)
  • Add socialregistration.contrib.openid.auth.OpenIDAuth to your AUTHENTICATION_BACKENDS
AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
    'socialregistration.contrib.openid.auth.OpenIDAuth',
)
  • Anywhere in your templates:
{% load openid %}
{% openid_form %}

Or

{% load openid %}
{% openid_form 'https://www.google.com/accounts/o8/id' 'login/with/google.png' %}

Tumblr

  • Add socialregistration.contrib.tumblr to your INSTALLED_APPS
INSTALLED_APPS = (
        'socialregistration',
        'socialregistration.contrib.tumblr'
)
  • Add socialregistration.contrib.tumblr.auth.TumblrAuth to your AUTHENTICATION_BACKENDS
AUTHENTICATION_BACKENDS = (
        'django.contrib.auth.backends.ModelBackend',
        'socialregistration.contrib.tumblr.auth.TumblrAuth',
)
  • Add your API keys:
TUMBLR_CONSUMER_KEY = ''
TUMBLR_CONSUMER_SECRET_KEY = ''
  • Anywhere in your templates:
{% load tumblr %}
{% tumblr_button %}

Or:

{% load tumblr %}
{% tumblr_button 'custom/button/image.png' %}

Twitter

  • Add socialregistration.contrib.twitter to your INSTALLED_APPS
INSTALLED_APPS = (
        'socialregistration',
        'socialregistration.contrib.twitter'
)
  • Add socialregistration.contrib.twitter.auth.TwitterAuth to your AUTHENTICATION_BACKENDS
AUTHENTICATION_BACKENDS = (
        'django.contrib.auth.backends.ModelBackend',
        'socialregistration.contrib.twitter.auth.TwitterAuth',
)
  • Add your API keys:
TWITTER_CONSUMER_KEY = ''
TWITTER_CONSUMER_SECRET_KEY = ''
  • Anywhere in your templates:
{% load twitter %}
{% twitter_button %}

Or:

{% load twitter %}
{% twitter_button 'custom/button/image.png' %}

API

Clients

Base

OAuth

OAuth 2

Mixins

Signals

Socialregistration comes with two signals that you can subscribe to:

socialregistration.signals.connect

The connect signal is fired every time a new social profile of sorts is created. The signal handler should accept four arguments. An additional fifth, the current request object, is passed in too:

from socialregistration import signals
from socialregistration.contrib.facebook.models import FacebookProfile

def connect_handler(sender, user, profile, client, request = None, **kwargs):
        data = client.graph.request('me')

signals.connect.connect(connect_handler, sender = FacebookProfile,
        dispatch_uid = 'facebook.connect')
socialregistration.signals.login

The login signal is fired every time a user signs into your Django application via a third party API. The signal handler here should also accept four arguments and take an optional fifth argument, being the current request:

def login_handler(sender, user, profile, client, request = None, **kwargs):
        data = client.graph.request('me')

signals.login.connect(login_handler, sender = FacebookProfile,
        dispatch_uid = 'facebook.connect')

Tests

Views

Settings

socialregistration.conf.settings.SOCIALREGISTRATION_USE_HTTPS
Default:False

Whether your callback URLs are served via SSL.

socialregistration.conf.settings.SOCIALREGISTRATION_SESSION_KEY
Default:'socialreg:'

The session key prefix to store temporary user information with while the user is setting up an account.

socialregistration.conf.settings.SOCIALREGISTRATION_GENERATE_USERNAME
Default:False

If set to True the username will be generated automatically

socialregistration.conf.settings.SOCIALREGISTRATION_GENERATE_USERNAME_FUNCTION
Default:'socialregistration.utils.generate_username'

If SOCIALREGISTRATION_GENERATE_USERNAME is True, this function will be called and should return a username. The function will receive three arguments:

  • A user model
  • A profile model
  • An API client
socialregistration.conf.settings.SOCIALREGISTRATION_SETUP_FORM
Default:'socialregistration.forms.UserForm'

IF SOCIALREGISTRATION_GENERATE_USERNAME is False, this form will be used to capture data from the user, such as username and email address.

socialregistration.conf.settings.SOCIALREGISTRATION_INITIAL_DATA_FUNCTION
Default:None

A function that should return some initial data for the SOCIALREGISTRATION_SETUP_FORM. The function takes four parameters:

  • The request object
  • A user model
  • A profile model
  • An API client

API

socialregistration Package

socialregistration Package

forms Module

mixins Module

utils Module

socialregistration.utils.generate_username(user, profile, client)[source]

Default function to generate usernames using the built in uuid library.

views Module

Subpackages

clients Package

clients Package
oauth Module

templatetags Package

templatetags Package
class socialregistration.templatetags.ButtonTag(template_name, params=[])[source]

Bases: django.template.base.Node

render(context)[source]
socialregistration.templatetags.button(template_name)[source]
socialregistration.templatetags.get_bits(token)[source]
socialregistration.templatetags.resolve(what, context)[source]

socialregistration.contrib Packages

facebook Package

auth Module
client Module
middleware Module
models Module
views Module

foursquare Package

auth Module
client Module
models Module
views Module

github Package

auth Module
client Module
models Module
views Module

linkedin Package

auth Module
client Module
models Module
views Module

openid Package

auth Module
client Module
models Module
storage Module
views Module

tumblr Package

auth Module
client Module
models Module
views Module

twitter Package

auth Module
client Module
models Module
views Module

Made by Caffeinehit Ltd.