|
|
|
|
@ -43,12 +43,22 @@ class BuiltinToolManageService:
|
|
|
|
|
get builtin tool provider oauth client schema
|
|
|
|
|
"""
|
|
|
|
|
provider = ToolManager.get_builtin_provider(provider_name, tenant_id)
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
|
|
is_oauth_custom_client_enabled = BuiltinToolManageService.is_oauth_custom_client_enabled(
|
|
|
|
|
tenant_id, provider_name
|
|
|
|
|
)
|
|
|
|
|
is_system_oauth_params_exists = BuiltinToolManageService.is_oauth_system_client_exists(provider_name)
|
|
|
|
|
result = {
|
|
|
|
|
"schema": provider.get_oauth_client_schema(),
|
|
|
|
|
"is_oauth_custom_client_enabled": BuiltinToolManageService.is_oauth_custom_client_enabled(
|
|
|
|
|
tenant_id, provider_name
|
|
|
|
|
),
|
|
|
|
|
"is_oauth_custom_client_enabled": is_oauth_custom_client_enabled,
|
|
|
|
|
"is_system_oauth_params_exists": is_system_oauth_params_exists,
|
|
|
|
|
}
|
|
|
|
|
if is_oauth_custom_client_enabled:
|
|
|
|
|
result["client_params"] = BuiltinToolManageService.get_oauth_client(tenant_id, provider_name)
|
|
|
|
|
result["redirect_uri"] = (
|
|
|
|
|
f"{dify_config.CONSOLE_API_URL}/console/api/oauth/plugin/{provider_name}/tool/callback"
|
|
|
|
|
)
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def list_builtin_tool_provider_tools(tenant_id: str, provider: str) -> list[ToolApiEntity]:
|
|
|
|
|
@ -415,6 +425,20 @@ class BuiltinToolManageService:
|
|
|
|
|
session.commit()
|
|
|
|
|
return {"result": "success"}
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def is_oauth_system_client_exists(provider_name: str) -> bool:
|
|
|
|
|
"""
|
|
|
|
|
check if oauth system client exists
|
|
|
|
|
"""
|
|
|
|
|
tool_provider = ToolProviderID(provider_name)
|
|
|
|
|
with Session(db.engine).no_autoflush as session:
|
|
|
|
|
system_client: ToolOAuthSystemClient | None = (
|
|
|
|
|
session.query(ToolOAuthSystemClient)
|
|
|
|
|
.filter_by(plugin_id=tool_provider.plugin_id, provider=tool_provider.provider_name)
|
|
|
|
|
.first()
|
|
|
|
|
)
|
|
|
|
|
return system_client is not None
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def is_oauth_custom_client_enabled(tenant_id: str, provider: str) -> bool:
|
|
|
|
|
"""
|
|
|
|
|
@ -685,4 +709,10 @@ class BuiltinToolManageService:
|
|
|
|
|
config=[x.to_basic_provider_config() for x in provider_controller.get_oauth_client_schema()],
|
|
|
|
|
cache=NoOpProviderCredentialCache(),
|
|
|
|
|
)
|
|
|
|
|
return encrypter.mask_tool_credentials(encrypter.decrypt(custom_oauth_client_params.oauth_params))
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
"oauth_params": encrypter.mask_tool_credentials(
|
|
|
|
|
encrypter.decrypt(custom_oauth_client_params.oauth_params)
|
|
|
|
|
),
|
|
|
|
|
"enabled": custom_oauth_client_params.enabled,
|
|
|
|
|
}
|
|
|
|
|
|