57 lines
1.6 KiB
Python
57 lines
1.6 KiB
Python
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
from yuxi.channel.extensions.feishu.client import get_client
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
FEISHU_SCOPES_TOOLS = [
|
|
{
|
|
"name": "feishu_scopes_check",
|
|
"description": "检查飞书应用的权限范围",
|
|
"parameters": {},
|
|
},
|
|
]
|
|
|
|
REQUIRED_SCOPES = [
|
|
"im:message",
|
|
"im:message:send_as_bot",
|
|
"im:chat",
|
|
"im:chat:readonly",
|
|
"contact:user:readonly",
|
|
"contact:user.id:readonly",
|
|
]
|
|
|
|
|
|
async def check_scopes(
|
|
app_id: str,
|
|
app_secret: str,
|
|
domain: str,
|
|
http_timeout_ms: int = 30000,
|
|
) -> dict:
|
|
try:
|
|
client = get_client(app_id, app_secret, domain, http_timeout_ms)
|
|
|
|
import lark_oapi
|
|
req = lark_oapi.auth.v3.GetAppAccessTokenInternalRequest(
|
|
request_body=lark_oapi.auth.v3.GetAppAccessTokenInternalRequestBody(
|
|
app_id=app_id,
|
|
app_secret=app_secret,
|
|
),
|
|
)
|
|
resp = await client.auth.v3.app_access_token.internal_async(req)
|
|
|
|
if resp.success() and resp.data:
|
|
return {
|
|
"success": True,
|
|
"message": "Application authentication is working correctly",
|
|
"required_scopes": REQUIRED_SCOPES,
|
|
}
|
|
else:
|
|
return {"success": False, "error": getattr(resp, "msg", "")}
|
|
except ImportError:
|
|
return {"success": False, "error": "lark-oapi SDK not installed"}
|
|
except Exception:
|
|
logger.exception("Feishu check_scopes error")
|
|
return {"success": False, "error": "Internal error"} |