Skip to main content

django-firebase-auth-sdk

Quantit Django 프로젝트에서 Firebase Authentication을 쉽게 통합할 수 있는 패키지입니다. Client에서 Firebase에게서 발급 받은 token을 바탕으로 사용자를 인증하고, 사용자 정보를 동기화합니다.

특징

  • Firebase ID 토큰 검증
  • Django 사용자 자동 생성 및 동기화
  • Global ID 지원하도록 BaseModel 클레스 제공

Requirements

  • Python ^3.12
  • Django >=5.1, <6.0
  • Firebase Admin SDK >=6.3, <7.0
  • GraphQL Core >=3.1, <3.3

설치

GitHub에서 직접 설치:

# pip 사용
pip install django-firebase-auth-sdk

# poetry 사용
poetry add django-firebase-auth-sdk

사용 방법

firebase admin sdk 설정(필수)

firebase admin sdk 설정이 필수적으로 필요합니다.

# settings.py
import firebase_admin
from firebase_admin import credentials

// ... existing code ...

cred = credentials.Certificate(f"path/to/serviceAccountKey.json")
firebase_admin.initialize_app(cred)

// ... existing code ...

앱 추가하기

앱 설정 파일에 아래 내용을 추가합니다.

# settings.py

// ... existing code ...

INSTALLED_APPS = [
    ...
    "django_firebase_auth",
    ...
]

// ... existing code ...

middleware 설정

settings.py에 작성한 middleware를 등록합니다.

# settings.py

// ... existing code ...

MIDDLEWARE = [
    ...
    "django_firebase_auth.auth.middleware.AuthenticationMiddleware",
    ...
]

// ... existing code ...

User 모델 설정

# settings.py

// ... existing code ...

AUTH_USER_MODEL = "django_firebase_auth.User"

// ... existing code ...

django_firebase_auth.User를 상속받은 커스텀 모델 역시 사용 가능합니다.

# models.py

from django_firebase_auth.models import User

class CustomUser(User):
    pass
# settings.py

// ... existing code ...

AUTH_USER_MODEL = "your_app.CustomUser"

// ... existing code ...

설정 옵션

아래와 같은 configure을 지원합니다.

# settings.py

// ... existing code ...
AUTHORIZATION_HEADER = "Authorization" # token이 포함된 헤더 이름, 기본값은 "Authorization"
AUTHORIZATION_HEADER_PREFIX = "Bearer" # token 앞에 붙는 접두사, 기본값은 "Bearer"

# 쿠키 설정
COOKIE_NAME = "firebase_auth_token" # 쿠키 이름, 기본값은 None. None일 경우 response에 쿠키를 추가하지 않음
COOKIE_MAX_AGE = 3600 # 쿠키 만료 시간, 기본값은 3600초(1시간)
COOKIE_HTTP_ONLY = True # 쿠키가 HTTP 전용인지 여부, 기본값은 True
COOKIE_SECURE = True # 쿠키가 HTTPS 전용인지 여부, 기본값은 True
COOKIE_SAMESITE = "Lax" # 쿠키의 SameSite 속성, 기본값은 "Lax"

# 사용자 자동 생성 여부
AUTO_CREATE_USER = True # 기본값은 False, 사용자 자동 생성 여부

# URL-safe Base64 사용 여부
USE_URL_SAFE_BASE64 = False # 기본값은 False, URL-safe Base64 사용 여부

// ... existing code ...

만일 AUTHORIZATION_HEADER를 따로 지정하시면서 CORS 설정이 되어 계시다면, CORS_ALLOW_HEADERS에 아래 값을 추가해주세요.

# settings.py

// ... existing code ...

CORS_ALLOW_HEADERS = [
    ...
    AUTHORIZATION_HEADER,
    ...
]

// ... existing code ...

사용자 생성 override

AuthenticationMiddleware에서 create_user 메서드를 override하여 사용자 생성 로직을 커스텀할 수 있습니다.

# middleware.py
from django_firebase_auth.auth.middleware import AuthenticationMiddleware

// ... existing code ...


class CustomAuthenticationMiddleware(AuthenticationMiddleware):
    def create_user(self, user_record: UserRecord):
        ...

// ... existing code ...

rest framework 사용 시

rest framework 사용 시, 아래 라이브러리를 추가로 설치해주세요.

pip add django-rest-framework-sdk[rest]

settings.py 설정

settings.py에 아래 내용을 추가해주세요.

# settings.py

// ... existing code ...

INSTALLED_APPS = [
    ...
    "rest_framework",
    "drf_yasg", # swagger 사용 시 필요(optional)
    ...
]

REST_FRAMEWORK = {
    "DEFAULT_AUTHENTICATION_CLASSES": [
        "django_firebase_auth.auth.authentication.TokenAuthentication",
    ],
}

// ... existing code ...

Metadata

Release files for django-firebase-auth-sdk 0.2.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-firebase-auth-sdk 0.2.6
File Size Uploaded Provenance Actions
django_firebase_auth_sdk-0.2.6.tar.gz 9.6 kB Without provenance Details for django_firebase_auth_sdk-0.2.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-firebase-auth-sdk 0.2.6
File Interpreter ABI Platform Actions
django_firebase_auth_sdk-0.2.6-py3-none-any.whl Python 3 none any Details for django_firebase_auth_sdk-0.2.6-py3-none-any.whl

Total release size: 21.9 kB

Release files / django_firebase_auth_sdk-0.2.6.tar.gz

Download URL django_firebase_auth_sdk-0.2.6.tar.gz
Size 9.6 kB
Tags Source
SHA-256 checksum
How to use checksums
e7d1d3357fa9b968bc38785377c91c50942823fe52ffb20408344f1dd2a3cfc5
BLAKE2b-256 checksum
How to use checksums
2757c49fc545d043141649e30a05447d7178d21b21b879a197e703a7e5162d6c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.7

Release files / django_firebase_auth_sdk-0.2.6-py3-none-any.whl

Download URL django_firebase_auth_sdk-0.2.6-py3-none-any.whl
Size 12.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4877dcdf609a0b62867a12536714d477f1f01708c12c39306ea9e988c8a36cf9
BLAKE2b-256 checksum
How to use checksums
284c3ec5d8be16a2e81fa77f4fc2f963f58edd7c26516ffc6aea891f40b033fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.7

Security for django-firebase-auth-sdk 0.2.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page