px普贤教程PuXian
普贤教程 › 包参考

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_ccurl, client_id, client_secret, scope=""
oa_token_passwordurl, client_id, client_secret, username, password, scope=""
其余 16 个 def(内部与辅助,可直接调用但不属稳定接口)
函数参数
oa_pcts
oa_formparams
oa_posturl, form
oa_jsonbody
oa_parse_tokenr, url
oa_token_refreshurl, client_id, client_secret, refresh_token, scope=""
oa_token_authcodeurl, client_id, client_secret, code, redirect_uri, code_verifier=""
oa_pkce_verifierlength=43
oa_pkce_challengeverifier
oa_pkce_generate
oa_build_auth_urlauth_url, client_id, redirect_uri, state, scope="", code_challenge="", code_challenge_method=""
oa_introspecturl, client_id, client_secret, token
oa_userinfourl, access_token
oa_is_expiredtoken, obtained_at_ms
oa_token_infotoken
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 编码,自实现)。
============================================================