Project import generated by Copybara.
GitOrigin-RevId: 63746295f1a5ab5a619056791995793d65529e62
diff --git a/src/ajax/startwebauthnauthentication.php b/src/ajax/startwebauthnauthentication.php
new file mode 100644
index 0000000..7dd504e
--- /dev/null
+++ b/src/ajax/startwebauthnauthentication.php
@@ -0,0 +1,16 @@
+<?php
+require_once(__DIR__."/../core.php");
+
+if (!secondFactor::isAvailable() || security::userType() !== security::UNKNOWN || !isset($_SESSION["firstfactorid"]) || !secondFactor::isEnabled($_SESSION["firstfactorid"]) || !secondFactor::hasSecurityKeys($_SESSION["firstfactorid"]) || $_SERVER['REQUEST_METHOD'] !== "POST") {
+ api::error();
+}
+
+try {
+ $result = secondFactor::createValidationChallenge();
+} catch (Throwable $e) {
+ api::error($conf['debug'] ? $e->getMessage() : null);
+}
+
+if (isset($result->publicKey)) $result->publicKey->rpId = ($conf["secondFactor"]["origin"] ?? null);
+
+api::write($result);