Giter Club home page Giter Club logo

django-facebook's Introduction

Facebook integration for your Django website

This library is deprecated. For Facebook integration, please use facebook-sdk. For questions about integrating Facebook and Django, please visit the PythonforFacebook Google Group.

Installation:

Simply add django_facebook to your INSTALLED_APPS and configure the following settings:

FACEBOOK_APP_ID = ''
FACEBOOK_SECRET_KEY = ''

# Optionally set default permissions to request, e.g: ['email', 'user_about_me']
FACEBOOK_SCOPE = []

# And for local debugging, use one of the debug middlewares and set:
FACEBOOK_DEBUG_TOKEN = ''
FACEBOOK_DEBUG_UID = ''
FACEBOOK_DEBUG_COOKIE = ''
FACEBOOK_DEBUG_SIGNEDREQ = ''

# Optionally throw exceptions instead of returning HTTP errors on signed request issues
FACEBOOK_RAISE_SR_EXCEPTIONS = True

Templates:

A few helpers for using the Javascript SDK can be enabled by adding this to your base template in the <head> section:

{% load facebook %}
{% facebook_init %}
    {% block facebook_code %}{% endblock %}
{% endfacebook %}

And this should be added just before your </html> tag:

{% facebook_load %}

The facebook_load template tag inserts the code required to asynchronously load the facebook javascript SDK. The facebook_init tag calls FB.init with your configured application settings. It is best to put your facebook related javascript into the facebook_code region so that it can be called by the asynchronous handler.

You may find the facebook_scope tag useful, which takes the setting in FACEBOOK_SCOPE and prints the extended permissions out in a comma-separated list.

<fb:login-button show-faces="false" width="200" max-rows="1"
  scope="{% facebook_scope %}"></fb:login-button>

A helpful debugging page to view the status of your facebook login can be enabled by adding this to your url configuration:

(r'^facebook_debug/', direct_to_template, {'template':'facebook_debug.html'}),  

Once this is in place you are ready to start with the facebook javascript SDK!

This module also provides all of the tools necessary for working with facebook on the backend:

Middleware:

This provides seamless access to the Facebook Graph via request object.

If a user accesses your site with:

  • a valid cookie (Javascript SDK), or

  • a valid signed_request parameter (Facebook Canvas App), then your views will have access to request.facebook.graph and you can begin querying the graph immediately. For example, to get the users friends:

    def friends(request): if request.facebook: friends = request.facebook.graph.get_connections('me', 'friends')

To use the middleware, simply add this to your MIDDLEWARE_CLASSES: 'django_facebook.middleware.FacebookMiddleware'

FacebookDebugCookieMiddleware allows you to set a cookie in your settings file and use this to simulate facebook logins offline.

FacebookDebugTokenMiddleware allows you to set a uid and access_token to force facebook graph availability.

FacebookDebugCanvasMiddleware allows you to set a signed_request to mimic a page being loaded as a canvas inside Facebook.

Authentication:

This provides seamless integration with the Django user system.

If a user accesses your site with a valid facebook cookie, a user account is automatically created or retrieved based on the facebook UID.

To use the backend, add this to your AUTHENTICATION_BACKENDS: 'django_facebook.auth.FacebookBackend'

To automatically populate your User and Profile models with facebook data, use: 'django_facebook.auth.FacebookProfileBackend'

Don't forget to include the default backend if you want to use standard logins for users as well: 'django.contrib.auth.backends.ModelBackend'

Decorators:

@facebook_required is a decorator which ensures the user is currently logged in with facebook and has access to the facebook graph. It is a replacement for @login_required if you are not using the facebook authentication backend.

@canvas_only is a decorater to ensure the view is being loaded with a valid signed_request via Facebook Canvas. If signed_request is not found, the decorator will return a HTTP 400. If signed_request is found but the user has not authorised, the decorator will redirect the user to authorise.

django-facebook's People

Contributors

aidanlister avatar ash211 avatar martey avatar nickpack avatar rohanza avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

django-facebook's Issues

Skipping CSRF validation upon valid signed request

I just added a middleware class that prevents CSRF validation (by setting it as already checked) in case a valid signed request was found.
All the code is committed in my own django-facebook fork: https://github.com/rshk/django-facebook (I just changed the middleware module and README.md).

Now, I'm not sure what the exact procedure should be in order to integrate with mainstream (if you would like to), since
I'm quite new to the whole git/github thing; should I submit a pull request? How do I do that?

Anyways, the changes I made consist just in an extra middleware class, so you could just copy-paste that.

FacebookMiddleware calls facebook.get_user_from_cookie on every request

which is bad, as facebook.get_user_from_cookie makes an urlrequest (see https://github.com/pythonforfacebook/facebook-sdk/blob/e81a0c14d58881c975ccb50aa336b3b76099c3ea/facebook.py#L372

So all requests to my site create a request to facebook. This will probably get my ip banned by fb when running a high traffic site.

Next to that, it is probably not necessary. Once we got the user authentication through the cookie, we know what user we are dealing with.

So I suggest not getting the fb_user if we already have a logged in user.

How to override FACEBOOK_DEFAULT_SCOPE

I put FACEBOOK_SCOPE in my settings.py but it is still using the default scope. Have searched the code for FACEBOOK_SCOPE and can't find it so is it the case that to override FACEBOOK_DEFAULT_SCOPE I have to do it specifically in the decorator etc.?

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.