Skip to main content

Custom Django Rest Framework authentication backend for parsing Firebase uid tokens and storing as local users.

Project description

DRF Firebase Auth


  • Python (tested with 2.7, 3.6)
  • Django
  • Django Rest Framework


$ pip install drf-firebase-auth

Add the application to your project's INSTALLED_APPS in


In your project's, add this to the REST_FRAMEWORK configuration. Note that if you want to retain access to the browsable API for locally created users, then you will probably want to keep rest_framework.authentication.SessionAuthentication too.


The drf_firebase_auth application comes with the following settings as default, which can be overridden in your project's file. Make sure to nest them within DRF_FIREBASE_AUTH as below:

    # path to JSON file with firebase secrets
    # allow creation of new local user in db
    # attempt to split firebase user.display_name and set local user
    # first_name and last_name
    # commonly JWT or Bearer (e.g. JWT <token>)
    # verify that JWT has not been revoked
    # require that firebase user.email_verified is True

You can get away with leaving all the settings as default except for FIREBASE_SERVICE_ACCOUNT_KEY, which is obviously required. As a minimum, you will need to set this in your project's This must be the JSON service account key that you receive from the Firebase console for your application.

    'FIREBASE_SERVICE_ACCOUNT_KEY': 'project/config/firebase.json'

Now that you have configured the application, run the migrations so that the Firebase data can be stored.

$ ./ migrate drf_firebase_auth

All you need to do now is have your client code handle the Firebase popup/redirect authentication flow, retrieve the idToken from the currentUser (Firebase explains this flow well in their docs:, and then use the idToken for the user in an Authorization header in requests to your API.

JWT <token>



  • Trello board created! Please follow this link if you wish to collabrate in the future direction of this package:
  • Please raise an issue/feature and name your branch 'feature-n' or 'issue-n', where 'n' is the issue number.
  • If you test this code with a Python version not listed above and all is well, please fork and update the README to include the Python version you used :)
  • I almost always setup Django with a custom user class inheriting from AbstractUser, where I switch the USERNAME_FIELD to be 'email'. This backend is setup to assign a username still anyway, but if there are any issues, please raise them and/or make a pull request to help the community!

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

drf-firebase-auth-0.0.8.tar.gz (12.3 kB view hashes)

Uploaded Source

Built Distribution

drf_firebase_auth-0.0.8-py3-none-any.whl (15.4 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