简单的OAuth2客户端。

feedr.oauth2的Python项目详细描述


馈线-oauth2

这是一个Python库,它实现了以下OAuth 2.0流的客户端:

  • 授权代码
  • 客户端凭据
  • 设备代码
  • 刷新令牌

{tha1}遵循标准中描述的^ a1}。在

快速启动

授权码

fromfeedr.oauth2.authorization_codeimportClient,PKCEclient=ac.Client(auth_uri='https://authorization-server.com/oauth2/authorize',token_uri='https://authorization-server.com/oauth2/token',client_id='...',client_secret='...',redirect_uri='...',use_pkce=True,)# ------------------# /api/login# ------------------request=client.authorization_request(scope='read+write',redirect_uri=EXTERNAL_URL+'/api/login/collect',)persist_state(request.state,request.pkce)returnredirect(request.auth_uri)# ------------------# /api/login/collect?code=...&state=...# ------------------pkce:PKCE=retrieve_state(state)response=client.authorization_code(code,pkce)print(response)# AccessTokenResponse(access_token='...', token_type='bearer', ...)

客户端凭据

^{pr2}$

设备代码

fromfeedr.oauth2.device_codeimportClientclient=Client(device_code_uri='https://authorization-server.com/device/code',token_uri='https://authorization-server.com/oauth2/token',client_id='...',client_secret='...',)request=client.get_device_code()print(f'Visit {request.verification_url} and enter the code {request.user_code}.')token_info=client.poll(request)print(token_info)# AccessTokenResponse(access_token='...', token_type='bearer', ...)

刷新令牌

authorization_code.Client类有一个refresh_token()方法,可以刷新 只需提供刷新令牌即可轻松访问令牌。在

new_token=client.refresh_token(token_info.refresh_token)

或者,refresh_token.Client可用于创建refresh_token请求。在

client=Client(token_uri='https://authorization-server.com/oauth2/token',refresh_token='...',client_id='...',client_secret='...',)token_info=client.get_token()print(token_info)# AccessTokenResponse(access_token='...', token_type='bearer', ...)

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
switchcase中的java Eclipse自动完成   如何使用Java字符串数组?   java Jenkins通过执行“git checkout f revision”打破了构建逻辑,如何禁用这种行为?   java E/Trace(20657):打开跟踪文件时出错:没有这样的文件或目录(2)   Java中毕达哥拉斯树的graphics2d可视化表示   java ImageView为空   java有办法改变安卓。R.布局。简单列表项目1,到我的自定义布局?   java错误:类型登录不是对象控制器的成员。应用程序(播放框架)   删除元素后的java Arraylist IndexOutOfBoundsException   java表整形   intellij idea测试脚本在使用java触发时失败。lang.ClassNotFoundException:oracle。jdbc。驾驶员OracleDriver错误消息   java类加载器:是否可以配置为使用惰性而非静态解析?   java RenderScript导致“缺少.rs.global_条目”的应用程序崩溃   java Spring安全性仅使用用户名登录,设置角色时不使用密码   java如何解决Talend中的“日期格式”问题   在安卓中使用outlook sdk对outlook执行java更新事件   java在调用start()之后,对组件调用了start()方法