Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
539 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/bash | ||
|
||
poetry config repositories.destrepo "${REPO_URL}" | ||
|
||
poetry publish \ | ||
--build \ | ||
--repository="destrepo" \ | ||
--username="__token__" \ | ||
--password="${PYPI_TOKEN}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Python: FastAPI", | ||
"type": "python", | ||
"request": "launch", | ||
"module": "uvicorn", | ||
"args": [ | ||
"app.main:app" | ||
], | ||
"jinja": true | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"python.testing.unittestEnabled": false, | ||
"python.testing.pytestEnabled": true | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from fastapi import FastAPI | ||
from fastapi.middleware import cors | ||
|
||
|
||
def get_app(): | ||
from app.router import router | ||
from fastapi_firebase import setup_firebase | ||
|
||
app = FastAPI( | ||
title="FastAPI firebase test app", | ||
description="Just a test app to check the firebase integration works.", | ||
) | ||
app.add_middleware( | ||
cors.CORSMiddleware, | ||
allow_origins=["*"], | ||
allow_headers=["*"], | ||
allow_methods=["*"], | ||
allow_credentials=True, | ||
expose_headers=["*"], | ||
) | ||
setup_firebase(app, "./.vscode/firebase.json") | ||
|
||
app.include_router(router, prefix="/firebase") | ||
|
||
return app | ||
|
||
|
||
app = get_app() | ||
|
||
if __name__ == "__main__": | ||
import uvicorn | ||
|
||
from app.settings import settings | ||
|
||
uvicorn.run( | ||
app, | ||
host=str(settings.HOST), | ||
port=settings.PORT, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from fastapi import APIRouter, Depends | ||
import typing | ||
from fastapi_firebase.auth import validate_token | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.get("/current-token") | ||
def current_token(data: typing.Dict[str, typing.Any] = Depends(validate_token)): | ||
return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import pydantic | ||
|
||
|
||
class AppSettings(pydantic.BaseSettings): | ||
PORT: int = pydantic.Field(8000) | ||
HOST: pydantic.IPvAnyAddress = pydantic.Field("0.0.0.0") | ||
|
||
|
||
settings = AppSettings() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,4 @@ | |
""" | ||
from .app import firebase_app, setup_firebase | ||
|
||
__version__ = "0.1.0" | ||
__version__ = "0.2.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import typing | ||
|
||
import firebase_admin | ||
import pydantic | ||
from fastapi import Depends, Security | ||
from fastapi.security.http import HTTPAuthorizationCredentials, HTTPBearer | ||
from firebase_admin import auth | ||
|
||
from .app import firebase_app | ||
from .schemes import TokenData | ||
|
||
token = HTTPBearer( | ||
scheme_name="firebaseIdToken", | ||
) | ||
|
||
|
||
def validate_token( | ||
token: HTTPAuthorizationCredentials = Security(token), | ||
app: firebase_admin.App = Depends(firebase_app), | ||
) -> typing.Dict[str, typing.Any]: | ||
return auth.verify_id_token(token.credentials, app) | ||
|
||
|
||
def token_info(token: typing.Dict[str, typing.Any] = Depends(validate_token)): | ||
return pydantic.parse_obj_as(TokenData, token) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import datetime | ||
import pydantic | ||
|
||
|
||
class TokenData(pydantic.BaseModel): | ||
provider_id: str | ||
issuer: pydantic.HttpUrl = pydantic.Field(..., alias="iss") | ||
audience: str = pydantic.Field(..., alias="aud") | ||
auth_time: datetime.datetime | ||
expires_at: datetime.datetime = pydantic.Field(..., alias="exp") | ||
issued_at: datetime.datetime = pydantic.Field(..., alias="iat") | ||
user_id: str | ||
sub: str |
Oops, something went wrong.