oauth
feishu.agent.oauth
¶
build_authorize_url_builder
¶
Python
build_authorize_url_builder(provider: UserTokenProvider, signer: OAuthStateSigner, redirect_uri: str) -> AuthorizeUrlBuilder
构建注入到工具上下文里的本轮授权 URL 生成器。
源代码位于: feishu/agent/oauth.py
preflight_authorization
async
¶
Python
preflight_authorization(agent: Any, event: Event, session_id: str, history: list[Message], call: ToolCall, tool: Tool, progress: _ProgressCard) -> Literal['suspended', 'blocked'] | None
工具执行 / 审批前检查用户授权;缺授权时先发授权卡片并挂起本轮。
源代码位于: feishu/agent/oauth.py
request_authorization
async
¶
Python
request_authorization(agent: Any, event: Event, session_id: str, history: list[Message], call: ToolCall, result: ToolResult, progress: _ProgressCard | None = None) -> bool
为缺少用户授权的工具创建挂起授权并发送授权卡片;返回是否已挂起本轮。
挂起记录先于卡片送达落库;OAuth callback 成功后调用 resume_authorization 恢复原工具调用。
源代码位于: feishu/agent/oauth.py
persist_authorization_card_message_id
async
¶
Python
persist_authorization_card_message_id(agent: Any, authorization: PendingAuthorization, message_id: str) -> None
Persist the sent auth-card message id without rewriting stale authorization state.
源代码位于: feishu/agent/oauth.py
build_authorize_url
¶
Python
build_authorize_url(agent: Any, user: Mapping[str, Any], scopes: tuple[str, ...], authorization: PendingAuthorization) -> str | None
调用产品注入的授权 URL 构造器,兼容二参旧签名与三参可恢复授权签名。
源代码位于: feishu/agent/oauth.py
send_auth_card
async
¶
向当前会话发送一张授权卡片;缺少构造器、客户端或 chat 时返回 False。
源代码位于: feishu/agent/oauth.py
try_send_auth_card
async
¶
发送授权卡片的不抛错封装:发送失败只记日志并返回 False。
源代码位于: feishu/agent/oauth.py
resume_authorization
async
¶
Python
resume_authorization(agent: Any, authorization_id: str, *, user: Mapping[str, Any] | None = None) -> str
OAuth callback 成功保存用户 token 后,恢复一次挂起授权对应的原工具调用。
返回机器可读状态;面向用户的最终结果发回原飞书会话。
源代码位于: feishu/agent/oauth.py
| Python | |
|---|---|
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | |
notify_authorization_resume_problem
async
¶
Python
notify_authorization_resume_problem(agent: Any, authorization: PendingAuthorization, text: str) -> None
在 OAuth 回调无法恢复已知 pending authorization 时,尽力向聊天里反馈状态。
源代码位于: feishu/agent/oauth.py
remove_authorization_card
async
¶
Python
remove_authorization_card(agent: Any, authorization: PendingAuthorization) -> None
授权完成后尽力清理独立 OAuth 授权卡片。
源代码位于: feishu/agent/oauth.py
event_from_pending_authorization
¶
Python
event_from_pending_authorization(authorization: PendingAuthorization) -> Event
从挂起授权记录重建原会话事件,供工具恢复与最终回复定位。
源代码位于: feishu/agent/oauth.py
oauth_callback_handler
¶
Python
oauth_callback_handler(provider: UserTokenProvider, signer: OAuthStateSigner, redirect_uri: str, *, on_authorized: AuthorizationResumeCallback | None = None, success_message: str = '授权成功,正在回到飞书继续处理。', success_title: str = '授权完成', invalid_state_message: str = '授权校验失败:state 无效或已过期,请重新发起授权。', missing_code_message: str = '授权失败:回调缺少 code。', exchange_error_message: str = '授权失败:换取用户凭证时出错,请稍后再试。', user_mismatch_message: str = '授权失败:完成授权的用户与发起授权的用户不一致。') -> Callable[[Any], Any]
创建用于用户态工具授权回调的 Starlette 兼容处理函数。