Skip to content

Commit 77c5427

Browse files
sergei-maertensclaudep
authored andcommitted
#701 -- Support WebAuthn 2.0
WebAuthn 2.0 refactored pydantic usage out of the codebase. For simplicity's sake, the minimum version is now set to 2.0 so that no compat layer is required. It appears that wat used to be Pydantic validation errors are now raised as InvalidJSONStructure exceptions, the form validation code is updated to reflect that.
1 parent dada714 commit 77c5427

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

requirements_dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ django-user-sessions
1515

1616
# Example app (WebAuthn)
1717

18-
webauthn~=1.11.0
18+
webauthn~=2.0.0
1919

2020
# Testing
2121

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
extras_require={
2222
'call': ['twilio>=6.0'],
2323
'sms': ['twilio>=6.0'],
24-
'webauthn': ['webauthn>=1.11.0,<1.99'],
24+
'webauthn': ['webauthn>=2.0,<2.99'],
2525
'yubikey': ['django-otp-yubikey'],
2626
'phonenumbers': ['phonenumbers>=7.0.9,<8.99'],
2727
'phonenumberslite': ['phonenumberslite>=7.0.9,<8.99'],

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ deps =
4848
dj50: Django<5.1
4949
djmain: https://github.com/django/django/archive/main.tar.gz
5050
yubikey: django-otp-yubikey
51-
webauthn: webauthn>=1.11.0,<1.99
51+
webauthn: webauthn>=2.0,<2.99
5252
webauthn: -rrequirements_e2e.txt
5353
coverage
5454
freezegun

two_factor/plugins/webauthn/forms.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
from django.utils import timezone
77
from django.utils.module_loading import import_string
88
from django.utils.translation import gettext_lazy as _
9-
from pydantic import ValidationError as PydanticValidationError
109
from webauthn.helpers.exceptions import (
11-
InvalidAuthenticationResponse, InvalidRegistrationResponse,
10+
InvalidAuthenticationResponse, InvalidJSONStructure,
11+
InvalidRegistrationResponse,
1212
)
1313
from webauthn.helpers.parse_authentication_credential_json import (
1414
parse_authentication_credential_json,
@@ -91,7 +91,7 @@ def _verify_token(self, user, token, device=None):
9191

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

9797
device.sign_count = new_sign_count
@@ -136,7 +136,7 @@ def clean_token(self):
136136

137137
try:
138138
parse_registration_credential_json(token)
139-
except InvalidRegistrationResponse as exc:
139+
except (InvalidJSONStructure, InvalidRegistrationResponse) as exc:
140140
raise forms.ValidationError(_('Entered token is not valid.'), code='invalid_token') from exc
141141

142142
self.cleaned_data = {

0 commit comments

Comments
 (0)