Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Added support for py webauthn 2.0+ #702

Merged
merged 2 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ django-user-sessions

# Example app (WebAuthn)

webauthn~=1.11.0
webauthn~=2.0.0

# Testing

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
extras_require={
'call': ['twilio>=6.0'],
'sms': ['twilio>=6.0'],
'webauthn': ['webauthn>=1.11.0,<1.99'],
'webauthn': ['webauthn>=2.0,<2.99'],
'yubikey': ['django-otp-yubikey'],
'phonenumbers': ['phonenumbers>=7.0.9,<8.99'],
'phonenumberslite': ['phonenumberslite>=7.0.9,<8.99'],
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ deps =
dj42: Django<5.0
djmain: https://github.com/django/django/archive/main.tar.gz
yubikey: django-otp-yubikey
webauthn: webauthn>=1.11.0,<1.99
webauthn: webauthn>=2.0,<2.99
webauthn: -rrequirements_e2e.txt
coverage
freezegun
Expand Down
8 changes: 4 additions & 4 deletions two_factor/plugins/webauthn/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from django.utils import timezone
from django.utils.module_loading import import_string
from django.utils.translation import gettext_lazy as _
from pydantic import ValidationError as PydanticValidationError
from webauthn.helpers.exceptions import (
InvalidAuthenticationResponse, InvalidRegistrationResponse,
InvalidAuthenticationResponse, InvalidJSONStructure,
InvalidRegistrationResponse,
)
from webauthn.helpers.parse_authentication_credential_json import (
parse_authentication_credential_json,
Expand Down Expand Up @@ -91,7 +91,7 @@ def _verify_token(self, user, token, device=None):

new_sign_count = verify_authentication_response(
device.public_key, device.sign_count, self.webauthn_rp, self.webauthn_origin, challenge, token)
except (PydanticValidationError, WebauthnDevice.DoesNotExist, InvalidAuthenticationResponse) as exc:
except (InvalidJSONStructure, WebauthnDevice.DoesNotExist, InvalidAuthenticationResponse) as exc:
raise forms.ValidationError(_('Entered token is not valid.'), code='invalid_token') from exc

device.sign_count = new_sign_count
Expand Down Expand Up @@ -136,7 +136,7 @@ def clean_token(self):

try:
parse_registration_credential_json(token)
except InvalidRegistrationResponse as exc:
except (InvalidJSONStructure, InvalidRegistrationResponse) as exc:
raise forms.ValidationError(_('Entered token is not valid.'), code='invalid_token') from exc

self.cleaned_data = {
Expand Down
2 changes: 1 addition & 1 deletion two_factor/plugins/webauthn/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def make_credential_creation_options(user, rp, excluded_credential_ids, challeng
creation_options = generate_registration_options(
rp_id=rp.id,
rp_name=rp.name,
user_id=user.id.decode('utf-8'),
user_id=user.id,
user_name=user.name,
user_display_name=user.display_name,
challenge=challenge,
Expand Down
Loading