blob: 7818a11aa07a35841c0908c4a67aa7f4bce2cb15 [file] [log] [blame]
Copybara botbe50d492023-11-30 00:16:42 +01001<?php
2require_once(__DIR__."/../core.php");
3security::checkType(security::WORKER, security::METHOD_NOTFOUND);
4secondFactor::checkAvailability();
5
6if ($_SERVER['REQUEST_METHOD'] !== "POST") {
7 api::error('This method should be called with POST.');
8}
9
10$input = api::inputJson();
11if ($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
16try {
17 $result = secondFactor::completeRegistrationChallenge($clientDataJSON, $attestationObject, $name);
18} catch (Throwable $e) {
19 api::error('An unexpected error occurred: ' . $e->getMessage());
20}
21
22api::write($result);