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, *, approved: PendingApproval | None = None) -> bool
为缺少用户授权的工具创建挂起授权并发送授权卡片;返回是否已挂起本轮。
挂起记录先于卡片送达落库;OAuth callback 成功后调用 resume_authorization 恢复原工具调用。
源代码位于: feishu/agent/oauth.py
| Python | |
|---|---|
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
cancel_pending_authorization
async
¶
Cancel only an awaiting authorization, preserving already claimed or unknown executions.
源代码位于: 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
¶
Python
send_auth_card(agent: Any, event: Event, authorize_url: str, progress: _ProgressCard | None = None) -> bool
向当前会话发送一张授权卡片;缺少构造器、客户端或 chat 时返回 False。
源代码位于: feishu/agent/oauth.py
try_send_auth_card
async
¶
Python
try_send_auth_card(agent: Any, event: Event, authorize_url: str, progress: _ProgressCard | None = None) -> bool
发送授权卡片的不抛错封装:发送失败只记日志并返回 False。
源代码位于: feishu/agent/oauth.py
resume_authorization
async
¶
Python
resume_authorization(agent: Any, authorization_id: str, *, user: Mapping[str, Any] | None = None) -> str
Serialize OAuth provenance validation, tool execution, and history continuation with session resets.
源代码位于: feishu/agent/oauth.py
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, *, card: dict[str, Any] | None = None) -> 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 兼容处理函数。