mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-25 10:29:14 -04:00
rename webauthn auth functions
_complete_webauthn_authentication -> _verify_webauthn_authentication This function just does verification of the actual auth process - checking the challenge is correct, the signature matches the public key we have stored in our database, etc. verify_webauthn_login -> _complete_webauthn_login_attempt This function doesn't do any actual verification, we've already verified the user is who they say they are (or not), it's about marking the attempt, either unsuccessful (we bump the failed_login_count in the db) or successful (we set the logged_in_at and current_session_id in the db). This change also informs changes to the names of methods on the user model and in user_api_client.
This commit is contained in:
@@ -91,8 +91,8 @@ def webauthn_complete_authentication():
|
||||
abort(403)
|
||||
|
||||
try:
|
||||
_complete_webauthn_authentication(user_to_login)
|
||||
redirect = _verify_webauthn_login(user_to_login)
|
||||
_verify_webauthn_authentication(user_to_login)
|
||||
redirect = _complete_webauthn_login_attempt(user_to_login)
|
||||
except Forbidden:
|
||||
# We don't expect to reach this case in normal situations - normally errors (such as using the wrong
|
||||
# security key) will be caught in the browser inside `window.navigator.credentials.get`, and the js will
|
||||
@@ -112,7 +112,11 @@ def webauthn_complete_authentication():
|
||||
return cbor.encode({'redirect_url': redirect.location}), 200
|
||||
|
||||
|
||||
def _complete_webauthn_authentication(user):
|
||||
def _verify_webauthn_authentication(user):
|
||||
"""
|
||||
Check that the presented security key is valid, has signed the right challenge, and belongs to the user
|
||||
we're trying to log in.
|
||||
"""
|
||||
state = session.pop("webauthn_authentication_state")
|
||||
request_data = cbor.decode(request.get_data())
|
||||
|
||||
@@ -127,22 +131,21 @@ def _complete_webauthn_authentication(user):
|
||||
)
|
||||
except ValueError as exc:
|
||||
current_app.logger.info(f'User {user.id} could not sign in using their webauthn token - {exc}')
|
||||
user.verify_webauthn_login(is_successful=False)
|
||||
user.complete_webauthn_login_attempt(is_successful=False)
|
||||
abort(403)
|
||||
|
||||
|
||||
def _verify_webauthn_login(user):
|
||||
def _complete_webauthn_login_attempt(user):
|
||||
"""
|
||||
* check the user hasn't gone over their max logins
|
||||
* check that the user's email is validated
|
||||
* if succesful, update current_session_id, log in date, and then redirect
|
||||
|
||||
"""
|
||||
redirect_url = request.args.get('next')
|
||||
|
||||
# normally API handles this when verifying an sms or email code but since the webauthn logic happens in the
|
||||
# admin we need a separate call that just finalises the login in the database
|
||||
logged_in, _ = user.verify_webauthn_login()
|
||||
logged_in, _ = user.complete_webauthn_login_attempt()
|
||||
if not logged_in:
|
||||
# user account is locked as too many failed logins
|
||||
|
||||
|
||||
@@ -437,8 +437,8 @@ class User(JSONModel, UserMixin):
|
||||
self.id,
|
||||
)
|
||||
|
||||
def verify_webauthn_login(self, is_successful=True):
|
||||
return user_api_client.verify_webauthn_login(self.id, is_successful)
|
||||
def complete_webauthn_login_attempt(self, is_successful=True):
|
||||
return user_api_client.complete_webauthn_login_attempt(self.id, is_successful)
|
||||
|
||||
|
||||
class InvitedUser(JSONModel):
|
||||
|
||||
@@ -126,8 +126,9 @@ class UserApiClient(NotifyAdminAPIClient):
|
||||
raise e
|
||||
|
||||
@cache.delete('user-{user_id}')
|
||||
def verify_webauthn_login(self, user_id, is_successful):
|
||||
def complete_webauthn_login_attempt(self, user_id, is_successful):
|
||||
data = {'successful': is_successful}
|
||||
# TODO: Change this to `/complete/webauthn-login`
|
||||
endpoint = f'/user/{user_id}/verify/webauthn-login'
|
||||
try:
|
||||
self.post(endpoint, data=data)
|
||||
|
||||
Reference in New Issue
Block a user