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
- 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:
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
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
- 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
Other commands
# Run the tests
./manage.py test
# Lint the code
./lint.sh
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file django-graphene-firebase-auth-0.0.18.tar.gz
.
File metadata
- Download URL: django-graphene-firebase-auth-0.0.18.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.26.0 rfc3986/1.5.0 tqdm/4.64.0 urllib3/1.26.7 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 309ea3eb7d48e6fc7159a9d22167fae7b4b8c6a296976fa4ce0d79062803daa3 |
|
MD5 | d7e39a8aa23b150ca01a8efb66576754 |
|
BLAKE2b-256 | 7acf1d2f4096a54e3b0f3d8340f27c31de30c55076cb9b0cbd7c98f614235a68 |