<?php
$creds = json_decode(file_get_contents('/etc/menlo/conf/test_page_secrets', false), true);
$url = 'https://recaptchaenterprise.googleapis.com/v1/projects/normal-kodiak-ably/assessments?key='
  . $creds['recaptcha_enterprise_invisible']['secret_key'];
$data = ["event" => [
  "token" => $_POST['menlo-captcha-token'],
  "expectedAction" => "submit",
  "siteKey" => $creds['recaptcha_enterprise_invisible']['site_key']
]];

// use key 'http' even if you send the request to https://...
$options = [
  'http' => [
    'header' => "Content-type: application/json\r\n",
    'method' => 'POST',
    'content' => json_encode($data),
  ],
];

$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === false) {
  echo 'Assessment creation failed';
} else {
  header('Content-Type: application/json');
  echo $result;
}
?>
