blob: 8996d4276b00acda9604bce0388f1dad966fb8cf [file] [log] [blame]
Copybara botbe50d492023-11-30 00:16:42 +01001<?php
2require_once(__DIR__."/../core.php");
3
4if (!secondFactor::isAvailable() || security::userType() !== security::UNKNOWN || !isset($_SESSION["firstfactorid"]) || !secondFactor::isEnabled($_SESSION["firstfactorid"]) || !secondFactor::hasSecurityKeys($_SESSION["firstfactorid"]) || $_SERVER['REQUEST_METHOD'] !== "POST") {
5 api::error();
6}
7
8$input = api::inputJson();
9if ($input === false || !isset($input["id"]) || !isset($input["clientDataJSON"]) || !isset($input["authenticatorData"]) || !isset($input["signature"])) api::error();
10$id = (string)$input["id"];
11$clientDataJSON = (string)$input["clientDataJSON"];
12$authenticatorData = (string)$input["authenticatorData"];
13$signature = (string)$input["signature"];
14
15try {
16 $result = secondFactor::completeValidationChallenge($id, $clientDataJSON, $authenticatorData, $signature);
17} catch (Throwable $e) {
18 api::error($conf['debug'] ? $e->getMessage() : null);
19}
20
21api::write($result);