Skip to content

Commit

Permalink
- commit code fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
maycuatroi committed Feb 24, 2024
1 parent 3888ccb commit 00cd36a
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 6 deletions.
2 changes: 1 addition & 1 deletion django_firebase_auth/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .settings import *
from .settings import *
13 changes: 9 additions & 4 deletions django_firebase_auth/firebase_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@
import firebase_admin.auth

from abstract_auth.abstract_auth import AbstractAuthentication
from django_firebase_auth.models import AuthFirebaseProfile
from django_firebase_auth.models import UserFirebaseProfile


class FirebaseAuthentication(AbstractAuthentication):
def _get_or_create_profile(self, user, uid):
return AuthFirebaseProfile.objects.get_or_create(
token_post_index_name = 'firebase_auth_token'
def _get_or_create_profile(self, user, uid,avatar:str):
return UserFirebaseProfile.objects.update_or_create(
user=user,
defaults={
"uid": uid,
"photo_url": avatar,
}
)[0]

def _verify_token(self, id_token):
return firebase_admin.auth.verify_id_token(id_token)
return firebase_admin.auth.verify_id_token(id_token, check_revoked=False)
3 changes: 2 additions & 1 deletion django_firebase_auth/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from abstract_auth.abstract_user_profile import AbstractAuthProfile


class AuthFirebaseProfile(AbstractAuthProfile):
class UserFirebaseProfile(AbstractAuthProfile):
class Meta:
app_label = "django_firebase_auth"
abstract = False
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from django.utils.translation import gettext_lazy as _
from rest_framework import serializers



class FirebaseAuthTokenSerializer(serializers.Serializer):
firebase_auth_token = serializers.CharField()

def validate(self, attrs):
firebase_auth_token = attrs.get("firebase_auth_token")
if firebase_auth_token is None:
msg = _('Must include "firebase_auth_token".')
raise serializers.ValidationError(msg, code="authorization")
attrs["user"] = self.context["user"]
return attrs
8 changes: 8 additions & 0 deletions django_firebase_auth/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.urls import path
from django_firebase_auth.viewsets.firebase_auth_viewset import FirebaseAuthViewSet

app_name = 'firebase_auth'
urlpatterns = [
path('login/', FirebaseAuthViewSet.as_view(), name='login'),
# path('logout/', FirebaseAuthLogoutViewSet.as_view(), name='logout'),
]
Empty file.
13 changes: 13 additions & 0 deletions django_firebase_auth/viewsets/firebase_auth_logout_viewset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from rest_framework import viewsets


class FirebaseAuthLogoutViewSet(viewsets.ViewSet):
"""
This viewset is used to logout the user from the firebase.
"""

def create(self, request):
"""
This method is used to logout the user from the firebase.
"""
pass
17 changes: 17 additions & 0 deletions django_firebase_auth/viewsets/firebase_auth_viewset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from rest_framework import permissions
from rest_framework.authtoken.views import ObtainAuthToken

from django_firebase_auth.firebase_auth import FirebaseAuthentication
from django_firebase_auth.serializers.firebase_authentication_serializer import (
FirebaseAuthTokenSerializer,
)


class FirebaseAuthViewSet(ObtainAuthToken):
permission_classes = (permissions.AllowAny,)
authentication_classes = [FirebaseAuthentication]
serializer_class = FirebaseAuthTokenSerializer

def get_serializer_context(self):
user = self.request.user
return {"user": user}

0 comments on commit 00cd36a

Please sign in to comment.