Run container with uvicorn, move templates for packaging, add systemd config for container deployment, add OIDC_TEST_SETTINGS_FILE env var for setting, misc fixes
This commit is contained in:
parent
170e663ee8
commit
57681d91fe
12 changed files with 146 additions and 49 deletions
|
@ -1,4 +1,9 @@
|
|||
"""
|
||||
Test of OpenId Connect & OAuth2 with FastAPI
|
||||
"""
|
||||
|
||||
from typing import Annotated
|
||||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
import logging
|
||||
from urllib.parse import urlencode
|
||||
|
@ -30,7 +35,7 @@ from .database import db
|
|||
# logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
templates = Jinja2Templates("src/templates")
|
||||
templates = Jinja2Templates(Path(__file__).parent / "templates")
|
||||
|
||||
|
||||
app = FastAPI(
|
||||
|
@ -79,6 +84,7 @@ async def login(request: Request, oidc_provider_id: str) -> RedirectResponse:
|
|||
auth token that only we can decode and contains userinfo,
|
||||
and a redirect to our own /auth/{oidc_provider_id} url
|
||||
"""
|
||||
breakpoint()
|
||||
redirect_uri = request.url_for("auth", oidc_provider_id=oidc_provider_id)
|
||||
try:
|
||||
provider_: StarletteOAuth2App = getattr(authlib_oauth, oidc_provider_id)
|
||||
|
@ -120,12 +126,13 @@ async def auth(request: Request, oidc_provider_id: str) -> RedirectResponse:
|
|||
user = await db.add_user(sub, user_info=userinfo, oidc_provider=oidc_provider)
|
||||
request.session["token"] = userinfo["sub"]
|
||||
await db.add_token(token, user)
|
||||
return RedirectResponse(url="/")
|
||||
return RedirectResponse(url=request.url_for("home"))
|
||||
else:
|
||||
# Not sure if it's correct to redirect to plain login
|
||||
# if no userinfo is provided
|
||||
redirect_uri = request.url_for("login", oidc_provider_id=oidc_provider_id)
|
||||
return RedirectResponse(url=redirect_uri)
|
||||
return RedirectResponse(
|
||||
url=request.url_for("login", oidc_provider_id=oidc_provider_id)
|
||||
)
|
||||
|
||||
|
||||
@app.get("/non-compliant-logout")
|
||||
|
@ -267,7 +274,7 @@ def main():
|
|||
import sys
|
||||
from importlib.metadata import version
|
||||
|
||||
print(version("sms_handler"))
|
||||
print(version("oidc-fastapi-test"))
|
||||
sys.exit(0)
|
||||
|
||||
run(app, host=args.host, port=args.port)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue