diff --git a/src/api/core/webauthn.rs b/src/api/core/webauthn.rs index 766efa3e..d7aedcd9 100644 --- a/src/api/core/webauthn.rs +++ b/src/api/core/webauthn.rs @@ -135,43 +135,43 @@ async fn post_webauthn_attestation_options( challenge.public_key.pub_key_cred_params = vec![ PubKeyCredParams { alg: COSEAlgorithm::ES256 as i64, - type_: "public-key".to_string(), + type_: "public-key".to_owned(), }, PubKeyCredParams { alg: COSEAlgorithm::ES384 as i64, - type_: "public-key".to_string(), + type_: "public-key".to_owned(), }, PubKeyCredParams { alg: COSEAlgorithm::ES512 as i64, - type_: "public-key".to_string(), + type_: "public-key".to_owned(), }, PubKeyCredParams { alg: COSEAlgorithm::RS256 as i64, - type_: "public-key".to_string(), + type_: "public-key".to_owned(), }, PubKeyCredParams { alg: COSEAlgorithm::RS384 as i64, - type_: "public-key".to_string(), + type_: "public-key".to_owned(), }, PubKeyCredParams { alg: COSEAlgorithm::RS512 as i64, - type_: "public-key".to_string(), + type_: "public-key".to_owned(), }, PubKeyCredParams { alg: COSEAlgorithm::PS256 as i64, - type_: "public-key".to_string(), + type_: "public-key".to_owned(), }, PubKeyCredParams { alg: COSEAlgorithm::PS384 as i64, - type_: "public-key".to_string(), + type_: "public-key".to_owned(), }, PubKeyCredParams { alg: COSEAlgorithm::PS512 as i64, - type_: "public-key".to_string(), + type_: "public-key".to_owned(), }, PubKeyCredParams { alg: COSEAlgorithm::EDDSA as i64, - type_: "public-key".to_string(), + type_: "public-key".to_owned(), }, ]; @@ -216,13 +216,12 @@ async fn post_webauthn( // Retrieve and delete the saved challenge state from the database let type_ = TwoFactorType::WebauthnPasskeyRegisterChallenge as i32; - let credential = match TwoFactor::find_by_user_and_type(&user.uuid, type_, &conn).await { - Some(tf) => { - let state: PasskeyRegistration = serde_json::from_str(&tf.data)?; - tf.delete(&conn).await?; - WEBAUTHN_PASSWORDLESS.finish_passkey_registration(&data.device_response.into(), &state)? - } - None => err!("No registration challenge found. Please try again."), + let credential = if let Some(tf) = TwoFactor::find_by_user_and_type(&user.uuid, type_, &conn).await { + let state: PasskeyRegistration = serde_json::from_str(&tf.data)?; + tf.delete(&conn).await?; + WEBAUTHN_PASSWORDLESS.finish_passkey_registration(&data.device_response.into(), &state)? + } else { + err!("No registration challenge found. Please try again.") }; WebauthnCredential::new( @@ -256,7 +255,7 @@ async fn post_webauthn_delete( data.validate(&user, false, &conn).await?; - WebauthnCredential::delete_by_uuid_and_user(&WebauthnCredentialId::from(uuid.to_string()), &user.uuid, &conn) + WebauthnCredential::delete_by_uuid_and_user(&WebauthnCredentialId::from(uuid.to_owned()), &user.uuid, &conn) .await?; Ok(Status::Ok) diff --git a/src/api/identity.rs b/src/api/identity.rs index 3d43801c..a6a36794 100644 --- a/src/api/identity.rs +++ b/src/api/identity.rs @@ -581,12 +581,12 @@ async fn webauthn_login(data: ConnectData, user_id: &mut Option, conn: & raw_state.get_mut("ast").and_then(|v| v.get_mut("credentials")).and_then(|v| v.as_array_mut()) { credentials.clear(); - for (_, passkey) in user_webauthn_credentials.iter() { + for (_, passkey) in &user_webauthn_credentials { let passkey_owned: Passkey = passkey.clone(); let cred = ::from(passkey_owned); credentials.push(serde_json::to_value(&cred)?); } - }; + } serde_json::from_value(raw_state)? } else { err!(