Coder Social home page Coder Social logo

django-facebook-auth's Introduction

django-facebook-auth

image

A stable Facebook authentication backend for Django >= 1.4.

Requires Celery for background token operations.

Installation

Package

django-facebook-auth can be installed as a normal Python package.

Example instalation for pip:

$ pip install django-facebook-auth

Configuration

Celery

This project requires working Celery integration. In case you are new to Celery, the First steps with Django tutorial will help you to hit the ground running.

settings.py

Set USE_TZ = True

Add facebook_auth to INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    'facebook_auth',
    ...
)

Add authentication backends to AUTHENTICATION_BACKENDS:

AUTHENTICATION_BACKENDS = (
    ...
    'facebook_auth.backends.FacebookBackend',
    'facebook_auth.backends.FacebookJavascriptBackend',
    ...
)

Set necessary Facebook properties:

FACEBOOK_CANVAS_URL = 'http://pozytywnie.pl/'  # root of your domain
FACEBOOK_APP_ID = '1234567890'
FACEBOOK_APP_SECRET = '91162629d258a876ee994e9233b2ad87'

Usage

The authentication flow is very straightforward:

  1. Redirect your user to Facebook OAuth endpoint using redirect_uri prepared with the help of this library.

    First in your view or context processor prepare the necessary parameters for the Facebook OAuth endpoint:

    from facebook_auth.urls import redirect_uri
    
    def login(request):
        ...
        context.update({
            'redirect_uri': redirect_uri('/login/success', '/login/fail'),
            'client_id': settings.FACEBOOK_APP_ID,
            'scope': 'email'
        })
        ...

    And embed the link in your template:

    <a href="https://www.facebook.com/dialog/oauth?client_id={{ client_id }}&amp;scope={{ scope }}&amp;redirect_uri={{ redirect_uri }}">Login using Facebook</a>
  2. User is redirected back to django-facebook-auth authentication handler, which either authenticates the user or refuses to do so.

    Prepare a separate view for each scenario.

  3. A best token for authenticated user is negotiated with Facebook in the background, using your Celery worker.

django-facebook-auth's People

Contributors

jellonek avatar jgoclawski avatar pazur avatar piotrkilczuk avatar riklaunim avatar tomwys avatar

Watchers

 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.