韦伯顿蟒蛇模块

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输入   检测*NIX上打开的端口时出现java问题   java捕获和保存屏幕截图   java SLF4JLogback:基于日志级别的多模式   Java从字符串中删除动态子字符串   在spring引导中contextLoads测试时运行java Liquibase   基于规则集的任意嵌套POJO的java任意就地转换   java如何做,边做边循环这段代码?   java是什么导致jmh测量中的错误?   java Spring RabbitTemplate执行方法可见性   java jms创建连接http超时weblogic   java如何在JMapViewer中的两点之间放置像箭头一样的图像   在我的形状计算器Java程序中使用带有Switch/Case语句的循环   字符串如何在Java中比较字符和数字