Files
dify/api/controllers/openapi/auth/data.py
T
+18 107bba0116 feat: dev snippet fronted (#36784)
Signed-off-by: dependabot[bot] <[email protected]>
Signed-off-by: EvanYao826 <[email protected]>
Co-authored-by: yyh <[email protected]>
Co-authored-by: 盐粒 Yanli <[email protected]>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Tianle <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Yunlu Wen <[email protected]>
Co-authored-by: zyssyz123 <[email protected]>
Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Co-authored-by: chariri <[email protected]>
Co-authored-by: Asuka Minato <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Co-authored-by: Nian <[email protected]>
Co-authored-by: 非法操作 <[email protected]>
Co-authored-by: Carmen Fernández Ruiz <[email protected]>
Co-authored-by: wangxiaolei <[email protected]>
Co-authored-by: QuantumGhost <[email protected]>
Co-authored-by: L1nSn0w <[email protected]>
Co-authored-by: Evan <[email protected]>
Co-authored-by: Escape0707 <[email protected]>
Co-authored-by: Jingyi <[email protected]>
Co-authored-by: Amr Sherif <[email protected]>
Co-authored-by: ZHOU ZHICHEN <[email protected]>
Co-authored-by: unknown <[email protected]>
Co-authored-by: JzoNg <[email protected]>
Co-authored-by: Xiyuan Chen <[email protected]>
Co-authored-by: -LAN- <[email protected]>
2026-05-28 17:34:14 +08:00

70 lines
1.9 KiB
Python

from __future__ import annotations
import uuid
from enum import StrEnum
from typing import Literal
from pydantic import BaseModel, ConfigDict, Field
from werkzeug.exceptions import InternalServerError
from configs import dify_config
from libs.oauth_bearer import Scope, TokenType
from models.account import Account, Tenant
from models.model import App, EndUser
from services.enterprise.enterprise_service import WebAppAccessMode
class Edition(StrEnum):
CE = "ce"
EE = "ee"
SAAS = "saas"
def current_edition() -> Edition:
if dify_config.EDITION == "CLOUD":
return Edition.SAAS
if dify_config.ENTERPRISE_ENABLED:
return Edition.EE
return Edition.CE
class ExternalIdentity(BaseModel):
model_config = ConfigDict(frozen=True)
email: str
issuer: str | None = None
class RequestContext(BaseModel):
model_config = ConfigDict(frozen=True)
token_type: TokenType
scope: Scope | None = None
path_params: dict[str, str]
class AuthData(BaseModel):
model_config = ConfigDict(arbitrary_types_allowed=True)
required_scope: Scope | None = None
token_type: TokenType
account_id: uuid.UUID | None = None
token_hash: str
token_id: uuid.UUID | None = None
scopes: frozenset[Scope]
tenants: dict[str, bool] = Field(default_factory=dict)
external_identity: ExternalIdentity | None = None
path_params: dict[str, str] = Field(default_factory=dict)
app: App | None = None
tenant: Tenant | None = None
app_access_mode: WebAppAccessMode | None = None
caller: Account | EndUser | None = None
caller_kind: Literal["account", "end_user"] | None = None
def require_app_context(self) -> tuple[App, Account | EndUser, Literal["account", "end_user"]]:
if self.app is None or self.caller is None or self.caller_kind is None:
raise InternalServerError("pipeline_invariant_violated: app context missing")
return self.app, self.caller, self.caller_kind