Skip to main content

Firebase authentication with django graphene

Project description

graphene-django-firebase-auth

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.

Compatibility

This code has only been tested with Python 3.7.0 and Django 2.1.2.

Installing

  1. Install the app:
pipenv install graphene-django-firebase-auth
  1. Download the JSON file from your Firebase console with your account's credentials.

  2. Set FIREBASE_KEY_FILE in your project's settings to the path of the credentials file:

FIREBASE_KEY_FILE = os.path.join(BASE_DIR, 'path/to/firebase-credentials.json')
  1. Add the authentication backend to AUTHENTICATION_BACKENDS:
AUTHENTICATION_BACKENDS = ['firebase_auth.authentication.FirebaseAuthentication']
  1. Add firebase_auth to INSTALLED_APPS:
INSTALLED_APPS = [
  '...',
  'firebase_auth',
]
  1. Add FirebaseAuthMixin to your AUTH_USER_MODEL:
class User(PermissionsMixin, FirebaseAuthMixin):
    # ...
  1. Build and run your DB migrations to add the changes:
./manage.py makemigrations
./manage.py migrate

Using the package

Once installed, authentication will be managed using this package. You can access info.context.user to add authentication logic, such as with the following:

def resolve_users(self, info, **kwargs):
    success = False

    if info.context.user.is_authenticated:
        success = True
    return success

Sending tokens on the client

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.

Developing

Setting up your environment

  1. Install the dependencies:
pipenv install -d
  1. Download the JSON file from your Firebase console with your account's credentials.

  2. Create an .env file using .env.example as a template. Make sure to specify the path to the file in the previous step.

  3. Enter the virtual environment:

./manage.py shell

Other commands

# Run the tests
./manage.py test
# Lint the code
./lint.sh

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-graphene-firebase-auth-0.0.7.tar.gz (7.5 kB view details)

Uploaded Source

File details

Details for the file django-graphene-firebase-auth-0.0.7.tar.gz.

File metadata

  • Download URL: django-graphene-firebase-auth-0.0.7.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.0.1 pkginfo/1.4.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.7

File hashes

Hashes for django-graphene-firebase-auth-0.0.7.tar.gz
Algorithm Hash digest
SHA256 c8bc808d35601028ccbaf7e02fe09ad3a3ba660228c2b79a6fca15e8e71a194a
MD5 4ac226c58bb44bb187818232cc86218c
BLAKE2b-256 13eb73e1dd03b41ed6d0942189cf352b347785652d2a3e7a5f97106d31db1a17

See more details on using hashes here.

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