SuperAPI AI 工具集

telnyx-oauth-python

编程与开发

查看项目

更新于 10-16 05:42

技能介绍

用途:为访问 Telnyx API 实现 OAuth 2.0 认证流程,资料以 Python SDK 示例形式给出,覆盖发现、授权、发令牌与客户端管理。

安装与初始化:pip install telnyx;随后用 from telnyx import Telnyx 创建 client,示例以 api_key=os.environ.get("TELNYX_API_KEY") 传入,并说明该参数为默认项、可省略。

主要能力:1) 发现类接口,GET /.well-known/oauth-authorization-server 返回 authorization_endpoint、token_endpoint、scopes_supported 等元数据;GET /.well-known/oauth-protected-resource 返回 authorization_servers、resource。2) 授权流程,客户端调用 client.oauth.retrieve_authorize 传 client_id、redirect_uri、response_type="code";可查询 consent_token 详情并用 client.oauth.grants 提交 allowed、consent_token 换取 redirect_uri。3) 令牌,client.oauth.token 支持 client_credentials 等 grant_type 及 code、code_verifier、refresh_token 等可选参数,返回 access_token、expires_in、refresh_token、token_type;client.oauth.introspect 校验令牌有效性并返回 active、client_id、scope、exp 等;GET /oauth/jwks 获取用于验签的 JWKS。4) 客户端注册与 CRUD,POST /oauth/register 动态注册(RFC 7591);client.oauth_clients 支持 list/create/retrieve/update/delete,返回 client_id、client_secret、client_type、redirect_uris、require_pkce 等。5) 授权管理,client.oauth_grants 支持 list/retrieve/delete,返回 client_id、scopes、last_used_at 等。

使用方式:所有示例假定 client 已按上述方式初始化;列表方法返回自动分页迭代器,可用 for item in page_result 遍历全部页面。

错误处理:代码应捕获 telnyx.APIConnectionError(网络错误)、telnyx.RateLimitError(429,需退避重试并参考 Retry-After)、telnyx.APIStatusError,并按状态码区分 401 无效密钥、403 权限不足、404 资源不存在、422 校验失败。

限制:资料仅给出 Python 示例与接口说明,未提供其他语言、价格、配额、具体授权码端点完整参数顺序及适用平台等信息。