Coder Social home page Coder Social logo

0101 / django-socialregistration Goto Github PK

View Code? Open in Web Editor NEW

This project forked from flashingpumpkin/django-socialregistration

1.0 3.0 0.0 248 KB

Combining OpenID, OAuth and FacebookConnect signup in one application

License: MIT License

Python 100.00%

django-socialregistration's Introduction

Django Social Registration

Django Social Registration enables developers to add alternative registration methods based on third party sites.

Supported methods currently are:

  • OpenID
  • OAuth
  • Facebook Connect

Requirements

Installation

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

Configuration

  1. Add socialregistration to your INSTALLED_APPS

  2. Add django.core.context_processors.request to the TEMPLATE_CONTEXT_PROCESSORS

  3. Include socialregistration.urls in your top level urls:

     urlpatterns = patterns('', 
     	# ...
     	url(r'^social/', include('socialregistration.urls')))
    
  4. Make sure you are using a RequestContext wherever you are planning to display the login buttons

     from django.template import RequestContext
    
     def login(request):
     	# ...
     	return render_to_response('login.html',
     		{}, context_instance = RequestContext(request))
    
  5. Once you're done, and configured, etc, don't forget to python manage.py syncdb your project.

Facebook Connect

Configuration

  1. Add the Facebook API keys to the your settings, variable names are

     FACEBOOK_APP_ID = ''
     FACEBOOK_API_KEY = ''
     FACEBOOK_SECRET_KEY = ''
    
  2. Add socialregistration.auth.FacebookAuth to AUTHENTICATION_BACKENDS

  3. Add socialregistration.middleware.FacebookMiddleware to MIDDLEWARE_CLASSES

  4. (Optional) Add FACEBOOK_REQUEST_PERMISSIONS to your settings. This is a comma seperated list of the permissions you need. e.g:

     FACEBOOK_REQUEST_PERMISSIONS = 'email,user_about_me'
    

Usage

  • Add tags to your template file

      {% load facebook_tags %}
      {% facebook_button %}
      {% facebook_js %}
    

    You can also specify your own custom button image by appending it to the facebook_button template tag:

      {% facebook_button 'http://example.com/other_facebook_button.png' %}
    

    You want to keep the {% facebook_js %} as far down in your HTML structure as possible to not impact the load time of the page.

    Also make sure you followed the steps to include a RequestContext in your template that is using these tags.

Twitter

Configuration

  1. Add the Twitter API keys and endpoints to your settings, variable names are

     TWITTER_CONSUMER_KEY = ''
     TWITTER_CONSUMER_SECRET_KEY = ''
     TWITTER_REQUEST_TOKEN_URL = ''
     TWITTER_ACCESS_TOKEN_URL = ''
     TWITTER_AUTHORIZATION_URL = ''
    
  2. Add socialregistration.auth.TwitterAuth to AUTHENTICATION_BACKENDS

  3. Add the right callback URL to your Twitter account

Usage

  • Add tags to your template file

      {% load twitter_tags %}
      {% twitter_button %}
    

    Same note here. Make sure you're serving the page with a RequestContext

    You can also specify your own custom button image by appending it to the twitter_button template tag:

      {% twitter_button 'http://example.com/other_twitter_button.png' %}
    

OAuth

Check out how the Twitter authentication works. Basically it's just plugging together some urls and creating an auth backend, a model and a view.

OpenID

Configuration

  • Add socialregistration.auth.OpenIDAuth to AUTHENTICATION_BACKENDS

Usage

  • Add tags to your template file

      {% load openid_tags %}
      {% openid_form %}
    

Logging users out

You can use the standard {% url auth_logout %}. Alternatively there is also {% url social_logout %} which is basically a wrapper around auth_logout.

This will log users only out of your site.

To make sure they're logged out of other sites too, use something like this:

	<a href="#" onclick:"javascript:FB.logout(function(resp){ document.location = '{% url social_logout %}'; })">Logout</a>

Or redirect them to the provider they logged in from.

Additional Settings

	SOCIALREGISTRATION_USE_HTTP = False
	SOCIALREGISTRATION_GENERATE_USERNAME = False

Set either True if you want to enable HTTPS or have the users skip the username form.

Signals

The app provides two signals that fire when users connect their accounts and log in:

	socialregistration.signals.connect
	socialregistration.signals.login

The signal handlers needs to accept three arguments, and can listen on specific profiles:

	from socialregistration import signals
	from socialregistration import models
	
	def connect_facebook(user, profile, client, **kwargs):
		# Do fancy stuff like fetching more user info with the client
		pass
	
	def login_facebook(user, profile, client, **kwargs):
		# Do fancy stuff like finding logged in friends
		pass
	
	signals.connect.connect(connect_facebook, sender = models.FacebookProfile)
	signals.login.connect(login_facebook, sender = models.FacebookProfile)

This works too with OpenID and OAuth profiles.

django-socialregistration's People

Contributors

adamfast avatar adrianribao avatar aljosa avatar claymation avatar dbrgn avatar devioustree avatar flashingpumpkin avatar muhuk avatar pinda avatar statico avatar thoblr avatar zerok avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.