Skip to main content

A GraphQL endpoint and authentication backend to signup or login a valid user access token from Facebook

Project description

Facebook Login

django-facebook-login provides a GraphQL mutation that takes a Facebook
user-access-token and the user's email and then does one of the following:

* Sign-up new user
* Connect existing Django user with their Facebook account
* Login existing, already connected Django user

In all cases, the user will be authenticated afterwards. This means, unlike
most other custom authentication backends, this backend will create a new
user if the given credentials (Facebook email + Facebook user access token)
are not known, yet.

Note that you still need extra code on your frontend that retrieves the user
access token from Facebook (i.e. the official Facebook login button).

Also note that this module assumes that the user has granted access to the
Facebook email. If a user disabled the email permission in the Facebook login
popup, this mutation will not work. You will need to show an error message
on the frontend and ask the user to try again, but this time please grant
the email permission.

Finally, please note that we don't use JWT in our projects. We use Django's
normal session based auth. Therefore, our mutation does not return anything.
You could easily write your own `CustomFacebookAuthMutation`, copy all our
code but after the `success_handler()` call you could do something else with
the user, i.e. create a JWT token and return it.

Quick start

1. Add "facebook-login" to your INSTALLED_APPS setting like this::


1. Add the `FacebookAuthBackend` to your `AUTHENTICATION_BACKENDS` setting::


1. Hook up the mutation in your GraphQL schema::

# in your main ``:
import graphene
from facebook_login import schema as fb_login

class Mutation(

class Queries(...):

schema = graphene.Schema(query=Queries, mutation=Mutation)

1. Run `python migrate` to create the FacebookAccount table.

1. Configure the app in your ``::

# Get these values from


This app uses the following settings:


Default: `facebook_login.utils.success_handler`


Default: `''`


**KeyError: 'password'**

If this happens, chances are that you are using `django-allauth`. Their
authentication backend crashes when Django's `authenticate()` function is
called without a `username` and `password` keyword-argument. As a workaround,
you can just make sure that `facebook_login.auth_backends.FacebookAuthBackend`
appears before other authentication backends.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-facebook-login-1.0.1.tar.gz (10.7 kB view hashes)

Uploaded Source

Built Distribution

django_facebook_login-1.0.1-py3-none-any.whl (13.3 kB view hashes)

Uploaded Python 3

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