mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-06 16:38:24 -04:00
DRY attested webauthn creds data
This commit is contained in:
@@ -28,10 +28,7 @@ def webauthn_begin_register():
|
|||||||
"name": current_user.email_address,
|
"name": current_user.email_address,
|
||||||
"displayName": current_user.name,
|
"displayName": current_user.name,
|
||||||
},
|
},
|
||||||
credentials=[
|
credentials=current_user.webauthn_credentials_as_cbor,
|
||||||
credential.to_credential_data()
|
|
||||||
for credential in current_user.webauthn_credentials
|
|
||||||
],
|
|
||||||
user_verification="discouraged", # don't ask for PIN
|
user_verification="discouraged", # don't ask for PIN
|
||||||
authenticator_attachment="cross-platform",
|
authenticator_attachment="cross-platform",
|
||||||
)
|
)
|
||||||
@@ -74,10 +71,7 @@ def webauthn_begin_authentication():
|
|||||||
abort(403)
|
abort(403)
|
||||||
|
|
||||||
authentication_data, state = current_app.webauthn_server.authenticate_begin(
|
authentication_data, state = current_app.webauthn_server.authenticate_begin(
|
||||||
credentials=[
|
credentials=user_to_login.webauthn_credentials_as_cbor,
|
||||||
credential.to_credential_data()
|
|
||||||
for credential in user_to_login.webauthn_credentials
|
|
||||||
],
|
|
||||||
user_verification=None, # required, preferred, discouraged. sets whether to ask for PIN
|
user_verification=None, # required, preferred, discouraged. sets whether to ask for PIN
|
||||||
)
|
)
|
||||||
session["webauthn_authentication_state"] = state
|
session["webauthn_authentication_state"] = state
|
||||||
@@ -125,10 +119,7 @@ def _complete_webauthn_authentication(user):
|
|||||||
try:
|
try:
|
||||||
current_app.webauthn_server.authenticate_complete(
|
current_app.webauthn_server.authenticate_complete(
|
||||||
state=state,
|
state=state,
|
||||||
credentials=[
|
credentials=user.webauthn_credentials_as_cbor,
|
||||||
credential.to_credential_data()
|
|
||||||
for credential in user.webauthn_credentials
|
|
||||||
],
|
|
||||||
credential_id=request_data['credentialId'],
|
credential_id=request_data['credentialId'],
|
||||||
client_data=ClientData(request_data['clientDataJSON']),
|
client_data=ClientData(request_data['clientDataJSON']),
|
||||||
auth_data=AuthenticatorData(request_data['authenticatorData']),
|
auth_data=AuthenticatorData(request_data['authenticatorData']),
|
||||||
|
|||||||
@@ -353,6 +353,13 @@ class User(JSONModel, UserMixin):
|
|||||||
return [WebAuthnCredential(json) for json in
|
return [WebAuthnCredential(json) for json in
|
||||||
user_api_client.get_webauthn_credentials_for_user(self.id)]
|
user_api_client.get_webauthn_credentials_for_user(self.id)]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def webauthn_credentials_as_cbor(self):
|
||||||
|
return [
|
||||||
|
credential.to_credential_data()
|
||||||
|
for credential in self.webauthn_credentials
|
||||||
|
]
|
||||||
|
|
||||||
def serialize(self):
|
def serialize(self):
|
||||||
dct = {
|
dct = {
|
||||||
"id": self.id,
|
"id": self.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user