All Projects → duo-labs → Py_webauthn

duo-labs / Py_webauthn

Licence: bsd-3-clause
A WebAuthn Python module.

Programming Languages

python
139335 projects - #7 most used programming language
python3
1442 projects

Projects that are alternatives of or similar to Py webauthn

PyGLM
Fast OpenGL Mathematics (GLM) for Python
Stars: ✭ 167 (-38.15%)
Mutual labels:  pypi, pip
pystyle
The source of my Python library, pystyle.
Stars: ✭ 158 (-41.48%)
Mutual labels:  pypi, pip
pmm
PyPi Mirror Manager
Stars: ✭ 29 (-89.26%)
Mutual labels:  pypi, pip
Pyreportjasper
Python Reporting with JasperReports
Stars: ✭ 77 (-71.48%)
Mutual labels:  flask, pypi
poetry-setup
Generate setup.py (setuptools) from pyproject.toml (poetry)
Stars: ✭ 44 (-83.7%)
Mutual labels:  pypi, pip
Grest
Build REST APIs with Neo4j and Flask, as quickly as possible!
Stars: ✭ 102 (-62.22%)
Mutual labels:  flask, pypi
pypi-simple
PyPI Simple Repository API client library
Stars: ✭ 21 (-92.22%)
Mutual labels:  pypi, pip
Rules python
Experimental Bazel Python Rules
Stars: ✭ 233 (-13.7%)
Mutual labels:  pypi, pip
pipyuan
pipyuan 内置了国内常用的 pip 源, 你可以快速设置想要的源
Stars: ✭ 30 (-88.89%)
Mutual labels:  pypi, pip
pip-download
A wrapper for pip download in offline scenario.
Stars: ✭ 22 (-91.85%)
Mutual labels:  pypi, pip
Hermetica
📖Hermetica is scaffold tools, and wiki to implement better flask applications.
Stars: ✭ 66 (-75.56%)
Mutual labels:  flask, pip
pipsalabim
An assistant to guess your pip dependencies from your code, without using a requirements file.
Stars: ✭ 15 (-94.44%)
Mutual labels:  pypi, pip
Swagger Py Codegen
a Python web framework generator supports Flask, Tornado, Falcon, Sanic
Stars: ✭ 508 (+88.15%)
Mutual labels:  flask, pypi
yavdb
Yet Another Vulnerability Database
Stars: ✭ 14 (-94.81%)
Mutual labels:  pypi, pip
Pepy
pepy is a site to get statistics information about any Python package.
Stars: ✭ 369 (+36.67%)
Mutual labels:  flask, pip
ios2androidres
Copy iOS image resources to their appropriate Android directory
Stars: ✭ 20 (-92.59%)
Mutual labels:  pypi, pip
Audioowl
Fast and simple music and audio analysis using RNN in Python 🕵️‍♀️ 🥁
Stars: ✭ 151 (-44.07%)
Mutual labels:  pypi, pip
Fades
fades is a system that automatically handles the virtualenvs in the cases normally found when writing scripts and simple programs, and even helps to administer big projects.
Stars: ✭ 182 (-32.59%)
Mutual labels:  pypi, pip
pipx
Install and Run Python Applications in Isolated Environments
Stars: ✭ 5,698 (+2010.37%)
Mutual labels:  pypi, pip
rfc-bibtex
A command line tool that creates bibtex entries for IETF RFCs and Internet Drafts.
Stars: ✭ 43 (-84.07%)
Mutual labels:  pypi, pip

PyWebAuthn

.. image:: https://img.shields.io/pypi/v/webauthn.svg :target: https://pypi.python.org/pypi/webauthn :alt: PyPI

.. image:: https://img.shields.io/badge/license-BSD-blue.svg :target: https://raw.githubusercontent.com/duo-labs/py_webauthn/master/LICENSE :alt: GitHub license

PyWebAuthn is a Python module which can be used to handle WebAuthn <https://www.w3.org/TR/webauthn/>_ registration and assertion. Currently, WebAuthn is supported in Firefox <https://www.mozilla.org/en-US/firefox/new/>\ , Chrome <https://www.google.com/chrome/>\ , and Edge <https://www.microsoft.com/en-us/windows/microsoft-edge>_.

Installation

pip install webauthn

Usage

Generating credential options, (to be passed to navigator.credentials.create\ ):

.. code-block:: python

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

Creating a WebAuthnUser object. Used during the assertion (login) process:

.. code-block:: python

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)

Generating assertion options, (to be passed to navigator.credentials.get\ ):

.. code-block:: python

webauthn_assertion_options = webauthn.WebAuthnAssertionOptions( webauthn_user, challenge)

Verifying a registration response, (result of navigator.credentials.create\ ):

.. code-block:: python

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 Verification

try: webauthn_credential = webauthn_registration_response.verify() except Exception as e: return jsonify({'fail': 'Registration failed. Error: {}'.format(e)})

Create User

Verifying an assertion response, (result of navigator.credentials.get\ ):

.. code-block:: python

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 Verification

try: sign_count = webauthn_assertion_response.verify() except Exception as e: return jsonify({'fail': 'Assertion failed. Error: {}'.format(e)})

Update counter.

user.sign_count = sign_count

Flask Demo

There is a Flask <http://flask.pocoo.org/>_ demo available in the flask_demo directory. Follow these steps to run the Flask web app:

#. cd flask_demo #. pip install -r requirements.txt #. python create_db.py #. python app.py #. Go to https://localhost:5000 <https://localhost:5000>_ in your web browser. Try registering and logging in with a compatible U2F or WebAuthn authenticator. #. Profit?

Flask Demo (Docker)

To run the Flask <http://flask.pocoo.org/>_ demo with Docker <https://www.docker.com/>_\ :

#. Install Docker. #. docker-compose up -d #. Go to https://localhost:5000 <https://localhost:5000>_ in your web browser. Try registering and logging in with a compatible U2F or WebAuthn authenticator.

Demo Troubleshooting

By default, both the local and Docker demos try to run the web app using HTTPS. This may cause issues such as NET::ERR_CERT_AUTHORITY_INVALID on Chrome. To get around this issue on Chrome, you can do the following:

#. Generate a self-signed certificate through tools like mkcert_ #. Enable requests to localhost over HTTPS through the following flag: chrome://flags/#allow-insecure-localhost.

For Firefox, you should be able to proceed to the page being served by the Flask app by doing the following:

#. Clicking 'Advanced' #. Clicking 'Accept the Risk and Continue'.

.. _mkcert: https://github.com/FiloSottile/mkcert

Unit Tests

To run the unit tests, use the following command from the top directory:

python3 -m unittest

This will run both the py_webauthn library tests and the Flask demo tests.

Note

Currently, PyWebAuthn does not support performing the following verifications.

  • Token Binding ID <https://www.w3.org/TR/webauthn/#dom-collectedclientdata-tokenbindingid>_
  • Authenticator Extensions <https://www.w3.org/TR/webauthn/#dom-collectedclientdata-authenticatorextensions>_
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].