工作人员经一次性跳转进入本地 Dify。AI 智能体菜单去掉已停用项,文件页工具栏收进表头,并关闭快速入口。 Co-authored-by: Cursor <cursoragent@cursor.com>
33 lines
1002 B
Python
33 lines
1002 B
Python
from fastapi import APIRouter, Depends
|
|
from pydantic import BaseModel, Field
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.core.deps import require_staff
|
|
from app.db import get_db
|
|
from app.services import dify_sso as dify_sso_service
|
|
|
|
router = APIRouter(dependencies=[Depends(require_staff)])
|
|
|
|
|
|
class SsoOpenIn(BaseModel):
|
|
nextPath: str | None = Field(default="/apps", description="Dify console path after login")
|
|
|
|
|
|
def _actor_id(principal: dict = Depends(require_staff)) -> int:
|
|
try:
|
|
return int(principal["sub"])
|
|
except (TypeError, ValueError):
|
|
from fastapi import HTTPException
|
|
|
|
raise HTTPException(status_code=401, detail="登录已失效")
|
|
|
|
|
|
@router.post("/dify/sso")
|
|
def open_dify_sso(
|
|
body: SsoOpenIn,
|
|
actor_id: int = Depends(_actor_id),
|
|
db: Session = Depends(get_db),
|
|
) -> dict:
|
|
"""Issue a one-shot redirect URL that logs the current staff into Dify."""
|
|
return dify_sso_service.issue_redirect(db, user_id=actor_id, next_path=body.nextPath)
|