mirror of
https://github.com/langgenius/dify.git
synced 2026-05-20 16:57:01 +08:00
DeviceApproveApi + DeviceDenyApi (cookie-authed) move to
controllers/openapi/oauth_device/{approve,deny}.py. Decorator stack
preserved verbatim: setup_required → login_required →
account_initialization_required → bearer_feature_required →
rate_limit. Audit event names ('oauth.device_flow_approved' /
'oauth.device_flow_denied') unchanged so the OTel exporter
registration keeps routing them.
The legacy /console/api/oauth/device/{approve,deny} mounts are
re-registered on console_ns from the bottom of the new files via a
local-import _register_legacy_console_mount() helper. The local
import breaks an import cycle that would otherwise form: openapi
imports console.wraps for setup_required, console.__init__.py imports
console.auth.oauth_device, which would re-import the openapi class
mid-load. Deferring console_ns past the class definition resolves it.
console/auth/oauth_device.py becomes a 9-line placeholder (the
existing console.__init__.py `from .auth import (..., oauth_device,
...)` keeps loading until Phase F prunes the import).
Plan: docs/superpowers/plans/2026-04-26-openapi-migration.md (in difyctl repo).
35 lines
890 B
Python
35 lines
890 B
Python
from flask import Blueprint
|
|
from flask_restx import Namespace
|
|
|
|
from libs.external_api import ExternalApi
|
|
|
|
bp = Blueprint("openapi", __name__, url_prefix="/openapi/v1")
|
|
|
|
api = ExternalApi(
|
|
bp,
|
|
version="1.0",
|
|
title="OpenAPI",
|
|
description="User-scoped programmatic API (bearer auth)",
|
|
)
|
|
|
|
openapi_ns = Namespace("openapi", description="User-scoped operations", path="/")
|
|
|
|
from . import account, index
|
|
from .oauth_device import approve as oauth_device_approve
|
|
from .oauth_device import code as oauth_device_code
|
|
from .oauth_device import deny as oauth_device_deny
|
|
from .oauth_device import lookup as oauth_device_lookup
|
|
from .oauth_device import token as oauth_device_token
|
|
|
|
__all__ = [
|
|
"account",
|
|
"index",
|
|
"oauth_device_approve",
|
|
"oauth_device_code",
|
|
"oauth_device_deny",
|
|
"oauth_device_lookup",
|
|
"oauth_device_token",
|
|
]
|
|
|
|
api.add_namespace(openapi_ns)
|