韦伯顿蟒蛇模块
webauthn的Python项目详细描述
安装
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应用程序:
- cd flask_demo
- pip install -r requirements.txt
- python create_db.py
- python app.py
- 转到Web浏览器中的https://localhost:5000。尝试使用兼容的U2F或WebAuthn身份验证程序注册和登录。
- 利润?
烧瓶演示(Docker)
- 安装Docker。
- docker-compose up -d
- 转到Web浏览器中的https://localhost:5000。尝试使用兼容的U2F或WebAuthn身份验证程序注册和登录。