Skip to content

Commit

Permalink
Merge branch 'hotfix/0.2.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
francipvb committed Feb 15, 2022
2 parents 6d682a1 + b933106 commit f2f20b5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion fastapi_firebase/__init__.py
Expand Up @@ -6,4 +6,4 @@
"""
from .app import firebase_app, setup_firebase

__version__ = "0.2.1"
__version__ = "0.2.2"
15 changes: 13 additions & 2 deletions fastapi_firebase/auth.py
@@ -1,4 +1,5 @@
import typing
import fastapi

import firebase_admin
import pydantic
Expand All @@ -12,13 +13,23 @@
token = HTTPBearer(
scheme_name="firebaseIdToken",
)
_failed_auth_headers = {"WWW-Authenticate": "Bearer"}


def validate_token(
token: HTTPAuthorizationCredentials = Security(token),
credential: HTTPAuthorizationCredentials = Security(token),
app: firebase_admin.App = Depends(firebase_app),
) -> typing.Dict[str, typing.Any]:
return auth.verify_id_token(token.credentials, app)
try:
return auth.verify_id_token(credential.credentials, app)
except auth.InvalidIdTokenError:
raise fastapi.HTTPException(401, "Invalid token received.", _failed_auth_headers)
except auth.UserDisabledError:
raise fastapi.HTTPException(403, "The user has been disabled.")
except auth.RevokedIdTokenError:
raise fastapi.HTTPException(403, "The token has been revoked.")
except auth.ExpiredIdTokenError:
raise fastapi.HTTPException(403, "The token has expired.")


def token_info(token: typing.Dict[str, typing.Any] = Depends(validate_token)):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Expand Up @@ -9,7 +9,7 @@ exclude = [
]
name = "fastapi-firebase"
readme = "README.md"
version = "0.2.1"
version = "0.2.2"

[tool.poetry.dependencies]
fastapi = ">0.60.0<1.0.0"
Expand Down

0 comments on commit f2f20b5

Please sign in to comment.