Giter Site home page Giter Site logo

walison17 / django-rest-firebase-auth Goto Github PK

View Code? Open in Web Editor NEW
24.0 4.0 8.0 46 KB

Use firebase authentication with your django rest framework project

License: MIT License

Python 100.00%
django django-rest-framework authentication firebase-auth django-rest-firebase firebase-authentication python

django-rest-firebase-auth's Introduction

Django Rest Firebase Auth

Use firebase authentication with your django rest framework project

codecov

Requirements

  • Python >= 3.7
  • Django >= 2.2
  • Django Rest Framework

Installation

pip install django-rest-firebase-auth

On your project's settings.py add this to the REST_FRAMEWORK configuration

REST_FRAMEWORK = {
    ...
    "DEFAULT_AUTHENTICATION_CLASSES": [
        "firebase_auth.authentication.FirebaseAuthentication"
    ]
    ...
}

Get your admin credentials .json from the Firebase SDK and add them to your project

FIREBASE_AUTH = {
    "SERVICE_ACCOUNT_KEY_FILE": "path_to_your_credentials.json"
}

The django-rest-firebase-auth comes with the following settings as default, which can be overridden in your project's settings.py.

FIREBASE_AUTH = {
    "SERVICE_ACCOUNT_KEY_FILE": "",

    # require that user has verified their email
    "EMAIL_VERIFICATION": False
}

django-rest-firebase-auth's People

Contributors

dependabot[bot] avatar scottgigante avatar walison17 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

django-rest-firebase-auth's Issues

Publish workflow

Would be great to have a workflow to automate the release of new versions on pypi

Probable race condition at User creation

I believe this is a race condition:

  1. Two simultanous requests arrive from a new/unencountered user.
  2. authenticate_credentials() is called on both requests.
  3. User.DoesNotExist is raised on both requests, causing both to call to default implementation of create_user_from_firebase().
  4. User.objects.create(**fields) is called on both calls, with the same params.
  5. One request throws IntegrityError, as below.

Traceback:

File ".../firebase_auth/authentication.py", line 46, in authenticate
user = self.authenticate_credentials(payload)
File ".../firebase_auth/authentication.py", line 89, in authenticate_credentials
user = self.create_user_from_firebase(uid, firebase_user)
File ".../firebase_auth/authentication.py", line 130, in create_user_from_firebase
return User.objects.create(**fields)
File ".../python/lib/python3.8/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File ".../python/lib/python3.8/site-packages/django/db/models/query.py", line 447, in create
obj.save(force_insert=True, using=self.db)
File ".../python/lib/python3.8/site-packages/django/contrib/auth/base_user.py", line 67, in save
super().save(*args, **kwargs)
File ".../python/lib/python3.8/site-packages/django/db/models/base.py", line 753, in save
self.save_base(using=using, force_insert=force_insert,
File ".../python/lib/python3.8/site-packages/django/db/models/base.py", line 790, in save_base
updated = self._save_table(
File ".../python/lib/python3.8/site-packages/django/db/models/base.py", line 895, in _save_table
results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw)
File ".../python/lib/python3.8/site-packages/django/db/models/base.py", line 933, in _do_insert
return manager._insert(
File ".../python/lib/python3.8/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File ".../python/lib/python3.8/site-packages/django/db/models/query.py", line 1254, in _insert
return query.get_compiler(using=using).execute_sql(returning_fields)
File ".../python/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1397, in execute_sql
cursor.execute(sql, params)
File ".../python/lib/python3.8/site-packages/django/db/backends/utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File ".../python/lib/python3.8/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File ".../python/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File ".../python/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File ".../python/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
django.db.utils.IntegrityError: duplicate key value violates unique constraint "core_user_username_key"
DETAIL:  Key (username)=(<SNIP>) already exists.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.