Custom Django REST framework authentication backend for Firebase
Project description
# DRF Firebase Auth
## Requirements
* Python (tested with 3.6)
* Django
* Django Rest Framework
## Installation
```
$ pip install drf-firebase-auth
```
Add the application to your project's `INSTALLED_APPS` in `settings.py`.
```
INSTALLED_APPS = [
...
'drf_firebase_auth',
]
```
In your project's `settings.py`, 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.
```
REST_FRAMEWORK = {
...
'DEFAULT_AUTHENTICATION_CLASSES': [
...
'rest_framework.authentication.SessionAuthentication',
'drf_firebase_auth.authentication.FirebaseAuthentication',
]
}
```
The `drf_firebase_auth` application comes with the following settings as default, which can be overridden in your project's `settings.py` file. Make sure to nest them within `DRF_FIREBASE_AUTH` as below:
```
DRF_FIREBASE_AUTH = {
# path to JSON file with firebase secrets
'FIREBASE_SERVICE_ACCOUNT_KEY': '',
# allow creation of new local user in db
'FIREBASE_CREATE_LOCAL_USER': True,
# attempt to split firebase user.display_name and set local user
# first_name and last_name
'FIREBASE_ATTEMPT_CREATE_WITH_DISPLAY_NAME': True,
# commonly JWT or Bearer (e.g. JWT <token>)
'FIREBASE_AUTH_HEADER_PREFIX': 'JWT',
# verify that JWT has not been revoked
'FIREBASE_CHECK_JWT_REVOKED': True,
# require that firebase user.email_verified is True
'FIREBASE_AUTH_EMAIL_VERIFICATION': False
}
```
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 `settings.py`. This must be the JSON service account key that you receive from the Firebase console for your application.
```
...
DRF_FIREBASE_AUTH = {
'FIREBASE_SERVICE_ACCOUNT_KEY': 'project/config/firebase.json'
}
```
Now that you have configured the application, make and run the migrations so that the Firebase data can be stored.
```
$ ./manage.py makemigrations drf_firebase_auth
$ ./manage.py migrate drf_firebase_auth
```
## Publishing
`python setup.py sdist`
`twine upload dist/*`
## Requirements
* Python (tested with 3.6)
* Django
* Django Rest Framework
## Installation
```
$ pip install drf-firebase-auth
```
Add the application to your project's `INSTALLED_APPS` in `settings.py`.
```
INSTALLED_APPS = [
...
'drf_firebase_auth',
]
```
In your project's `settings.py`, 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.
```
REST_FRAMEWORK = {
...
'DEFAULT_AUTHENTICATION_CLASSES': [
...
'rest_framework.authentication.SessionAuthentication',
'drf_firebase_auth.authentication.FirebaseAuthentication',
]
}
```
The `drf_firebase_auth` application comes with the following settings as default, which can be overridden in your project's `settings.py` file. Make sure to nest them within `DRF_FIREBASE_AUTH` as below:
```
DRF_FIREBASE_AUTH = {
# path to JSON file with firebase secrets
'FIREBASE_SERVICE_ACCOUNT_KEY': '',
# allow creation of new local user in db
'FIREBASE_CREATE_LOCAL_USER': True,
# attempt to split firebase user.display_name and set local user
# first_name and last_name
'FIREBASE_ATTEMPT_CREATE_WITH_DISPLAY_NAME': True,
# commonly JWT or Bearer (e.g. JWT <token>)
'FIREBASE_AUTH_HEADER_PREFIX': 'JWT',
# verify that JWT has not been revoked
'FIREBASE_CHECK_JWT_REVOKED': True,
# require that firebase user.email_verified is True
'FIREBASE_AUTH_EMAIL_VERIFICATION': False
}
```
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 `settings.py`. This must be the JSON service account key that you receive from the Firebase console for your application.
```
...
DRF_FIREBASE_AUTH = {
'FIREBASE_SERVICE_ACCOUNT_KEY': 'project/config/firebase.json'
}
```
Now that you have configured the application, make and run the migrations so that the Firebase data can be stored.
```
$ ./manage.py makemigrations drf_firebase_auth
$ ./manage.py migrate drf_firebase_auth
```
## Publishing
`python setup.py sdist`
`twine upload dist/*`
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
drf-firebase-auth-0.0.1.tar.gz
(10.3 kB
view details)
File details
Details for the file drf-firebase-auth-0.0.1.tar.gz.
File metadata
- Download URL: drf-firebase-auth-0.0.1.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.31.0 CPython/3.6.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84b106ea64c27f585ec3d1e55a1dba760fd7f32555935725987272fbd2a968fa
|
|
| MD5 |
0778580efc9cd266ef5ad65e6337ede1
|
|
| BLAKE2b-256 |
9f83b1553f5b2c09d079f74c5fb28ceb66e86ecf51874404d8e05dc70b622b02
|