Fetch provider info at boot time: get public key from there instead of in settings
Some checks failed
/ build (push) Failing after 15s
/ test (push) Successful in 5s

This commit is contained in:
phil 2025-01-29 14:03:33 +01:00
parent 5b31ef888c
commit f910834736
3 changed files with 61 additions and 29 deletions

View file

@ -7,6 +7,7 @@ from pathlib import Path
from datetime import datetime
import logging
from urllib.parse import urlencode
from contextlib import asynccontextmanager
from httpx import HTTPError
from fastapi import Depends, FastAPI, HTTPException, Request, status
@ -32,10 +33,11 @@ from .auth_utils import (
hasrole,
get_current_user_or_none,
get_current_user,
get_resource_user,
get_user_from_token,
authlib_oauth,
get_token,
oidc_providers_settings,
get_providers_info,
)
from .auth_misc import pretty_details
from .database import db
@ -51,10 +53,18 @@ origins = [
"https://philo.ydns.eu/",
]
@asynccontextmanager
async def lifespan(app: FastAPI):
await get_providers_info()
yield
app = FastAPI(
title="OIDC auth test",
lifespan=lifespan
)
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
@ -278,7 +288,7 @@ async def get_resource_(
# user: Annotated[User, Depends(get_current_user)],
# oidc_provider: Annotated[StarletteOAuth2App, Depends(get_oidc_provider)],
# token: Annotated[OAuth2Token, Depends(get_token)],
user: Annotated[User, Depends(get_resource_user)],
user: Annotated[User, Depends(get_user_from_token)],
) -> JSONResponse:
"""Generic path for testing a resource provided by a provider"""
return JSONResponse(await get_resource(id, user))