I’m setting up a reCaptcha for a client with an Enterprise Google Cloud account.
I used an API Key, which is the easiest based on my client files configuration.
Everything works well until I call the https://recaptchaenterprise.googleapis.com/v1/projects/ url.
I get this error as my curl response :
{
"error": {
"code": 403,
"message": "Permission denied for: recaptchaenterprise.assessments.create. Please ensure you have sufficient permissions: https://cloud.google.com/iam/docs/granting-changing-revoking-access",
"status": "PERMISSION_DENIED"
}
}
Here’s my code :
$verify_url = "https://recaptchaenterprise.googleapis.com/v1/projects/PROJECT_ID/assessments?key=API_KEY";
$data = [
"event" => [
'expectedAction' => 'CONTACT_FORM',
"token" => $recaptcha_token,
'siteKey' => $google_site_key
]
];
$ch = curl_init($verify_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$response = curl_exec($ch);
curl_close($ch);
$response_data = json_decode($response);
I tried setting up a Service Account with “reCAPTCHA Enterprise Agent”
access rights but nothing works (and I don’t understand how the API Key is supposed to be linked to the Service Account).
I removed all restrictions from the API Key to test but it does not work.