Skip to main content

Django backend for Firebase custom authentication.

Project description

Django Firebase Custom Auth

Django backend for Firebase custom authentication.

Requirements

  • Django 3
  • Python 3

Setup

Install dependencies.

pip install djangorestframework firebase-admin

Install this package.

pip install django-firebase-custom-auth

Add django_firebase_custom_auth to your INSTALLED_APPS in your settings.py.

INSTALLED_APPS = (
    ...,
    'rest_framework',
    ...,
    'django_firebase_custom_auth',
)

Add URL patterns.

urlpatterns = [
    path('custom-auth/', include('django_firebase_custom_auth.urls')),
]

Specify a file path service account info is stored.

SERVICE_ACCOUNT_KEY_FILE_PATH = os.path.join(BASE_DIR, 'serviceAccountKey.json')

(Optional) Provide a key to generate a custom token. The default value is id. Make sure this value is a primary key your user model has.

CUSTOM_TOKEN_KEY = 'uuid'

Now you can send a user's credentials (username and password) from your Firebase client app to Django backend. And your server will return a custom token if the credentials are valid. And you can sign in with Firebase using the token. Below is an example in JavaScript.

const url = "http://127.0.0.1:8000/custom-auth/login/"
const credentials = {
	username: username,
	password: password,
}

axios.post(url, credentials).then((resp) => {
	const token = resp.data.token

	firebase.auth().signInWithCustomToken(token)
		.then(() => {
			// Sign in with Firebase
		})
		.catch((err) => {
			// Handle an error
		})
})

Use Case

Let's say your users will be added by admin manually and you want to authenticate users without email. Since Firebase built-in authentication requires email and password, you need a server that provides a custom token to authenticate users with Firebase. This package can handle the custom authentication. For more details, see these resources below.

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-firebase-custom-auth-0.1.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_firebase_custom_auth-0.1-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file django-firebase-custom-auth-0.1.tar.gz.

File metadata

  • Download URL: django-firebase-custom-auth-0.1.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.6.5

File hashes

Hashes for django-firebase-custom-auth-0.1.tar.gz
Algorithm Hash digest
SHA256 ba3ca2f73cd750f256e1f524dc5b2d7c66ff5dffd27db111b8fab427b0b1f517
MD5 c3c84fd2d85b3fe22d2ebc7f8c623e6d
BLAKE2b-256 42893f3b8c7e05a93c16d2cb2403f57b8db3405a332b48ed2165cddd5d8959a4

See more details on using hashes here.

File details

Details for the file django_firebase_custom_auth-0.1-py3-none-any.whl.

File metadata

  • Download URL: django_firebase_custom_auth-0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.6.5

File hashes

Hashes for django_firebase_custom_auth-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b9a0e09524f779b13e603e05bad301d86b5e4e8c647af92dffa2a48d6dd43e4f
MD5 42014abdb533df04f8a0c096ad1351c6
BLAKE2b-256 180b4580b10c8db068ccf2692a7df4dc4e2be781e19a9cdded3f98d6638ba791

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page