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)
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
from os import environ
|
||||
import string
|
||||
import random
|
||||
from typing import Type, Tuple
|
||||
from pathlib import Path
|
||||
|
||||
from pydantic import BaseModel, computed_field
|
||||
from pydantic_settings import (
|
||||
|
@ -56,7 +58,16 @@ class Settings(BaseSettings):
|
|||
init_settings,
|
||||
env_settings,
|
||||
file_secret_settings,
|
||||
YamlConfigSettingsSource(settings_cls, "settings.yaml"),
|
||||
YamlConfigSettingsSource(
|
||||
settings_cls,
|
||||
Path(
|
||||
Path(
|
||||
environ.get(
|
||||
"OIDC_TEST_SETTINGS_FILE", Path.cwd() / "settings.yaml"
|
||||
),
|
||||
)
|
||||
),
|
||||
),
|
||||
dotenv_settings,
|
||||
)
|
||||
|
||||
|
|
|
@ -9,6 +9,9 @@
|
|||
h1 {
|
||||
text-align: center;
|
||||
}
|
||||
.hidden {
|
||||
display: none;
|
||||
}
|
||||
.content {
|
||||
width: 100%;
|
||||
display: flex;
|
|
@ -46,7 +46,7 @@
|
|||
<a href="protected-by-foorole-or-barrole">Auth + foorole or barrole protected content</a>
|
||||
<a href="protected-by-barrole">Auth + barrole protected content</a>
|
||||
<a href="protected-by-foorole-and-barrole">Auth + foorole and barrole protected content</a>
|
||||
<a href="fast_api_depends">Using FastAPI Depends</a>
|
||||
<a href="fast_api_depends" class="hidden">Using FastAPI Depends</a>
|
||||
<a href="other">Other</a>
|
||||
</div>
|
||||
{% if user_info_details %}
|
Loading…
Add table
Add a link
Reference in a new issue