feat: add fixed questions and improve authentication
This commit is contained in:
1 parent
8af4fed89d
commit
4c9f75f31e
42 files changed
+4008
-200
No files matched your search
@@ -17,8 +17,8 @@ from typing import TYPE_CHECKING, TypeVar, cast
|
||||
from fastapi import FastAPI, HTTPException, Request
|
||||
from langgraph.types import Checkpointer
|
||||
|
||||
from deerflow.config.app_config import AppConfig
|
||||
from deerflow.persistence.feedback import FeedbackRepository
|
||||
from deerflow.config.app_config import AppConfig
|
||||
from deerflow.persistence.feedback import FeedbackRepository
|
||||
from deerflow.runtime import RunContext, RunManager, StreamBridge
|
||||
from deerflow.runtime.events.store.base import RunEventStore
|
||||
from deerflow.runtime.runs.store.base import RunStore
|
||||
@@ -94,11 +94,15 @@ async def langgraph_runtime(app: FastAPI) -> AsyncGenerator[None, None]:
|
||||
|
||||
app.state.run_store = RunRepository(sf)
|
||||
app.state.feedback_repo = FeedbackRepository(sf)
|
||||
else:
|
||||
from deerflow.runtime.runs.store.memory import MemoryRunStore
|
||||
|
||||
app.state.run_store = MemoryRunStore()
|
||||
app.state.feedback_repo = None
|
||||
else:
|
||||
from deerflow.runtime.runs.store.memory import MemoryRunStore
|
||||
|
||||
app.state.run_store = MemoryRunStore()
|
||||
app.state.feedback_repo = None
|
||||
|
||||
from deerflow.persistence.fixed_questions import make_fixed_question_store
|
||||
|
||||
app.state.fixed_question_store = make_fixed_question_store(sf)
|
||||
|
||||
from deerflow.persistence.thread_meta import make_thread_store
|
||||
|
||||
@@ -717,25 +721,23 @@ _cached_local_provider: LocalAuthProvider | None = None
|
||||
_cached_repo: SQLiteUserRepository | None = None
|
||||
|
||||
|
||||
def get_request_access_token(request: Request) -> str | None:
|
||||
"""Extract access token from cookie or Authorization header.
|
||||
|
||||
Priority:
|
||||
1. ``access_token`` cookie (browser session mode)
|
||||
2. ``Authorization: Bearer <token>`` header (API client mode)
|
||||
3. ``access_token`` query parameter for the WeKnora iframe bootstrap only
|
||||
"""
|
||||
cookie_token = request.cookies.get("access_token")
|
||||
if cookie_token:
|
||||
return cookie_token
|
||||
|
||||
authorization = request.headers.get("authorization", "").strip()
|
||||
if authorization:
|
||||
scheme, _, token = authorization.partition(" ")
|
||||
if scheme.lower() == "bearer":
|
||||
token = token.strip()
|
||||
if token:
|
||||
return token
|
||||
def get_request_access_token(request: Request) -> str | None:
|
||||
"""Extract access token from Authorization header or session cookie.
|
||||
|
||||
Priority:
|
||||
1. ``Authorization: Bearer <token>`` header (the caller/tab's explicit identity)
|
||||
2. ``access_token`` cookie (browser session fallback)
|
||||
3. ``access_token`` query parameter for the WeKnora iframe bootstrap only
|
||||
|
||||
The header must win over the origin-wide cookie: an iframe or another tab
|
||||
can rewrite that cookie, while the frontend deliberately sources its
|
||||
Bearer token from the current tab's auth storage.
|
||||
"""
|
||||
from app.gateway.auth.token_source import get_explicit_or_session_token
|
||||
|
||||
request_token = get_explicit_or_session_token(request)
|
||||
if request_token:
|
||||
return request_token
|
||||
|
||||
from app.gateway.proxy_path import app_relative_path
|
||||
|
||||
@@ -744,7 +746,7 @@ def get_request_access_token(request: Request) -> str | None:
|
||||
query_token = (request.query_params.get("access_token") or "").strip()
|
||||
if query_token:
|
||||
return query_token
|
||||
return None
|
||||
return None
|
||||
|
||||
|
||||
def get_local_provider() -> LocalAuthProvider:
|
||||
|
||||
Reference in new issue
Block a user