普贤教程 › 包参考
oauth2 包
OAuth 2.0 令牌获取
| 项 | 值 |
|---|---|
| 包名 | oauth2 |
| 版本 | 0.2.0 |
| 可用版本 | 0.1.0 / 0.2.0 |
| 入口 | oauth2.px |
| 分类 | 认证与安全 |
| 文件数 / 行数 | 1 / 220 |
安装与引入
bash
pxpkg init # 首次 pxpkg add oauth2@0.2.0 pxpkg install
px
import oauth2所属分类教程:认证与安全
公开接口
| 函数 | 参数 |
|---|---|
oa_token_cc | url, client_id, client_secret, scope="" |
oa_token_password | url, client_id, client_secret, username, password, scope="" |
其余 16 个 def(内部与辅助,可直接调用但不属稳定接口)
| 函数 | 参数 |
|---|---|
oa_pct | s |
oa_form | params |
oa_post | url, form |
oa_json | body |
oa_parse_token | r, url |
oa_token_refresh | url, client_id, client_secret, refresh_token, scope="" |
oa_token_authcode | url, client_id, client_secret, code, redirect_uri, code_verifier="" |
oa_pkce_verifier | length=43 |
oa_pkce_challenge | verifier |
oa_pkce_generate | |
oa_build_auth_url | auth_url, client_id, redirect_uri, state, scope="", code_challenge="", code_challenge_method="" |
oa_introspect | url, client_id, client_secret, token |
oa_userinfo | url, access_token |
oa_is_expired | token, obtained_at_ms |
oa_token_info | token |
oa_generate_state | |
包内说明(源码头注释)
text
============================================================ 普贤生态库:registry/oauth2 —— OAuth 2.0 令牌获取 ------------------------------------------------------------ 纯函数库(网络 IO:native http_request),编译(px build)与解释(px run)双模式一致。 oa_token_cc(url, client_id, client_secret[, scope]) → Ok(token dict) | Err client_credentials 模式(§4.4,服务端间调用常用) oa_token_password(url, client_id, client_secret, user, pw[, scope]) → Ok(token dict) | Err password 模式(§4.3) token dict = {access_token, token_type, expires_in, ...}(透传 JSON); 非 2xx / 响应缺 access_token → Err(error 字段带出)。 请求体 application/x-www-form-urlencoded(含 percent 编码,自实现)。 ============================================================