Authentication provider for graphene-django and Firebase's Authentication service.
Note this is a WIP and abandoned project since I never ended up using Firebase. But the code is still a good starting point as of writing this.
Partially inspired by django-firebase-auth for Django REST framework.
This app is used with Firebase Authentication on a client.
This code has only been tested with Python 3.7.0
and Django 2.1.2
.
- Install the app:
pipenv install graphene-django-firebase-auth
-
Download the JSON file from your Firebase console with your account's credentials.
-
Set
FIREBASE_KEY_FILE
in your project's settings to the path of the credentials file:
import os
FIREBASE_KEY_FILE = os.path.join(BASE_DIR, 'path/to/firebase-credentials.json')
- Add the authentication backend to
AUTHENTICATION_BACKENDS
:
AUTHENTICATION_BACKENDS = ['firebase_auth.authentication.FirebaseAuthentication']
- Add
firebase_auth
toINSTALLED_APPS
:
INSTALLED_APPS = [
'firebase_auth',
]
- Add
FirebaseAuthMixin
to yourAUTH_USER_MODEL
:
class User(PermissionsMixin, FirebaseAuthMixin):
- Build and run your DB migrations to add the changes:
./manage.py makemigrations
./manage.py migrate
Your client will need to send an Authorization: Bearer
token on each request. How you do this depends on your client
and is outside the scope
of this documentation.
- Install the dependencies:
pipenv install -d
-
Download the JSON file from your Firebase console with your account's credentials.
-
Create an
.env
file using.env.example
as a template. Make sure to specify the path to the file in the previous step. -
Enter the virtual environment:
./manage.py shell
# Run the tests
./manage.py test
# Lint the code
./lint.sh