Copybara bot | be50d49 | 2023-11-30 00:16:42 +0100 | [diff] [blame^] | 1 | <?php |
| 2 | require_once(__DIR__."/../core.php"); |
| 3 | security::checkType(security::WORKER, security::METHOD_NOTFOUND); |
| 4 | secondFactor::checkAvailability(); |
| 5 | |
| 6 | if ($_SERVER['REQUEST_METHOD'] !== "POST") { |
| 7 | api::error('This method should be called with POST.'); |
| 8 | } |
| 9 | |
| 10 | $input = api::inputJson(); |
| 11 | if ($input === false || !isset($input["clientDataJSON"]) || !isset($input["attestationObject"]) || !isset($input["name"])) api::error(); |
| 12 | $clientDataJSON = (string)$input["clientDataJSON"]; |
| 13 | $attestationObject = (string)$input["attestationObject"]; |
| 14 | $name = (string)$input["name"]; |
| 15 | |
| 16 | try { |
| 17 | $result = secondFactor::completeRegistrationChallenge($clientDataJSON, $attestationObject, $name); |
| 18 | } catch (Throwable $e) { |
| 19 | api::error('An unexpected error occurred: ' . $e->getMessage()); |
| 20 | } |
| 21 | |
| 22 | api::write($result); |