韦伯顿蟒蛇模块

webauthn的Python项目详细描述


pywebauthn

PyPIGitHub license

pywebauthn是一个python模块,可用于处理WebAuthn注册和断言。目前,FirefoxChromeEdge支持webauthn。

安装

pip install webauthn

用法

正在生成凭据选项,(传递给navigator.credentials.create):

make_credential_options=webauthn.WebAuthnMakeCredentialOptions(challenge,rp_name,rp_id,user_id,username,display_name,icon_url)

正在创建WebAuthnUser对象。在断言(登录)过程中使用:

webauthn_user=webauthn.WebAuthnUser(user.id,user.username,user.display_name,user.icon_url,user.credential_id,user.pub_key,user.sign_count,user.rp_id)

生成断言选项,(传递给navigator.credentials.get):

webauthn_assertion_options=webauthn.WebAuthnAssertionOptions(webauthn_user,challenge)

验证注册响应,(结果navigator.credentials.create):

webauthn_registration_response=webauthn.WebAuthnRegistrationResponse(RP_ID,ORIGIN,registration_response,challenge,trust_anchor_dir,trusted_attestation_cert_required,self_attestation_permitted,none_attestation_permitted,uv_required=False)# User Verificationtry:webauthn_credential=webauthn_registration_response.verify()exceptExceptionase:returnjsonify({'fail':'Registration failed. Error: {}'.format(e)})# Create User

验证断言响应,(结果navigator.credentials.get):

webauthn_user=webauthn.WebAuthnUser(user.ukey,user.username,user.display_name,user.icon_url,user.credential_id,user.pub_key,user.sign_count,user.rp_id)webauthn_assertion_response=webauthn.WebAuthnAssertionResponse(webauthn_user,assertion_response,challenge,origin,uv_required=False)# User Verificationtry:sign_count=webauthn_assertion_response.verify()exceptExceptionase:returnjsonify({'fail':'Assertion failed. Error: {}'.format(e)})# Update counter.user.sign_count=sign_count

烧瓶演示

flask_demo目录中有一个Flask演示。按照以下步骤运行Flask Web应用程序:

  1. cd flask_demo
  2. pip install -r requirements.txt
  3. python create_db.py
  4. python app.py
  5. 转到Web浏览器中的https://localhost:5000。尝试使用兼容的U2F或WebAuthn身份验证程序注册和登录。
  6. 利润?

烧瓶演示(Docker)

使用Docker运行Flask演示:

  1. 安装Docker。
  2. docker-compose up -d
  3. 转到Web浏览器中的https://localhost:5000。尝试使用兼容的U2F或WebAuthn身份验证程序注册和登录。

目前,pywebauthn不支持执行以下验证。

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

推荐PyPI第三方库


热门话题
内存Java正在运行。jar heapdump错误   java如何在安卓画布中弯曲文本区域?   java如何在Gdx 安卓游戏编程中获得矩形的真实触碰位置?   找不到java Spring MVC控制器   在Java中使用双重检查锁定单例扩展类   java在高效的时间和内存中动态执行insert(索引、数据)、delete(索引)、getAt(索引)操作。   java 安卓 Toast和视图帮助   java协议缓冲区:从文件中读取所有序列化消息   java如何在Jackson中为参数化接口类型执行通用自定义反序列化程序   与简单的空检查相比,使用(平面)映射的java优势是什么?   异步方法seam中的java Get contextparam   jar使用相同的java运行时运行另一个java程序   java访问Spring批处理中的作业参数   java给定字符串为空或null   在h2数据库1.4中找不到java类“org.h2.fulltext.FullTextLucene”。*不适用于Lucene Core 4*   java Spring Boot在使用@enableSync时不响应任何请求   java错误:在bash上找不到或加载主类pj2   “返回对象”和“返回(对象)”之间的Java差异   java Android开发:如何使用onKeyUp?