Project import generated by Copybara.

GitOrigin-RevId: 63746295f1a5ab5a619056791995793d65529e62
diff --git a/src/ajax/addsecuritykey2.php b/src/ajax/addsecuritykey2.php
new file mode 100644
index 0000000..7818a11
--- /dev/null
+++ b/src/ajax/addsecuritykey2.php
@@ -0,0 +1,22 @@
+<?php
+require_once(__DIR__."/../core.php");
+security::checkType(security::WORKER, security::METHOD_NOTFOUND);
+secondFactor::checkAvailability();
+
+if ($_SERVER['REQUEST_METHOD'] !== "POST") {
+  api::error('This method should be called with POST.');
+}
+
+$input = api::inputJson();
+if ($input === false || !isset($input["clientDataJSON"]) || !isset($input["attestationObject"]) || !isset($input["name"])) api::error();
+$clientDataJSON = (string)$input["clientDataJSON"];
+$attestationObject = (string)$input["attestationObject"];
+$name = (string)$input["name"];
+
+try {
+  $result = secondFactor::completeRegistrationChallenge($clientDataJSON, $attestationObject, $name);
+} catch (Throwable $e) {
+  api::error('An unexpected error occurred: ' . $e->getMessage());
+}
+
+api::write($result);