Remove frontend hack for requesting persistent browser sessions, part ii (backend) (#3052)

This commit is contained in:
Jonathan Dobson
2025-07-29 09:32:52 -04:00
committed by GitHub
parent d9537327da
commit 8ff1c5dfa2
6 changed files with 228 additions and 36 deletions

View File

@@ -86,6 +86,44 @@ async def _authenticate_helper(authorization: str) -> Organization:
return organization
async def get_current_user_id(
authorization: Annotated[str | None, Header(include_in_schema=False)] = None,
) -> str:
if not authorization:
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail="Invalid credentials",
)
return await _authenticate_user_helper(authorization)
async def get_current_user_id_with_authentication(
authorization: Annotated[str | None, Header()] = None,
) -> str:
if not authorization:
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail="Invalid credentials",
)
return await _authenticate_user_helper(authorization)
async def _authenticate_user_helper(authorization: str) -> str:
token = authorization.split(" ")[1]
if not app.authenticate_user_function:
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail="Invalid user authentication method",
)
user_id = await app.authenticate_user_function(token)
if not user_id:
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail="Invalid credentials",
)
return user_id
@cached(cache=TTLCache(maxsize=CACHE_SIZE, ttl=AUTHENTICATION_TTL))
async def _get_current_org_cached(x_api_key: str, db: AgentDB) -> Organization:
"""