0

I did follow their documentation on https://googleapis.dev/ruby/google-cloud-recaptcha_enterprise-v1/latest/index.html

I first added the env variable RECAPTCHA_ENTERPRISE_CREDENTIALS then run the

client = ::Google::Cloud::RecaptchaEnterprise::V1::RecaptchaEnterpriseService::Client.new

documentation says response = client.create_assessment request but documentation didn't add sample request so I did assume that it will look like in this documentation https://cloud.google.com/recaptcha-enterprise/docs/create-assessment

{
  "event": {
    "token": "token",
    "siteKey": "key"
  }
}

But when I execute the client.create_assessment it is giving me error ArgumentError: Unknown field name 'event' in initialization map entry.

I also tried to follow this https://googleapis.dev/ruby/google-cloud-recaptcha_enterprise-v1/latest/Google/Cloud/RecaptchaEnterprise/V1/RecaptchaEnterpriseService/Client.html#create_assessment-instance_method where the parameters is request and also gives me error ArgumentError: Unknown field name 'request' in initialization map entry.

What could be the correct parameter/request for creating assessment?

Gem I used is google-cloud-recaptcha_enterprise-v1 and google-cloud-recaptcha_enterprise

Jofre
  • 3,718
  • 1
  • 23
  • 31
bxorcloud
  • 659
  • 1
  • 7
  • 20

1 Answers1

1

So I solve this issue by using client.create_assessment(parent: "projects/{your project-id}", assessment: event) my event value was event = Google::Cloud::RecaptchaEnterprise::V1::Event.new(token: "token from execute", site_key: "your site key")

It solves the error and answers the question (but another error after this one occurred about permission denied). I Will update once resolved.

bxorcloud
  • 659
  • 1
  • 7
  • 20
  • 1
    Come back and help us! The docs for using enterprise recaptcha from outside of the GCP platform might as well be written in klingon – Adam Jenkins Apr 05 '21 at 16:22
  • @bxorcloud Did you manage to fix that permission denied issue? If yes, can you please update the answer? – Krishna Nov 29 '21 at 05:47
  • At least for me, it was a silly mistake. I was using credentials of different service account, which didn't have recaptcha role assigned to it. – Krishna Dec 05 '21 at 17:01
  • @Adam I had to go to IAM and assign the role of recaptch enterprise agent to the service account (even though I thought I did that upon creation, guess not) – marcopolo Jul 15 '22 at 07:24
  • @Krishna how did you specify the service account in the create_assessment call? I'm having the same permissions problem from both JavaScript (Node) client library (createAssessment) and directly calling the REST API equivalent. – Appurist - Paul W Nov 10 '22 at 16:48
  • @Appurist-PaulW As far as I can recall, the client used env variable `GOOGLE_APPLICATION_CREDENTIALS`. This var would point to a json file, which has "client_email" field mentioning service account mail. That json file has other field as well like(type, project_id, private_key, etc).. I think you can download that json file somewhere from console. Please refer doc for that. – Krishna Nov 11 '22 at 08:27
  • 1
    Thanks @Krishna. I was using AWS Lambda and thus needed a solution without the credentials as a file, and without relying on a client lib to recognize an environment variable, since the Enterprise client lib doesn't work on third-party (non-GCP) hosts like AWS. In the end, I realized I had to use the REST API from Lambda, and found that I could use the API key instead, if I passed it in the REST URL "?key=blah". That turned out to be the simplest solution for me. It is working now, finally. – Appurist - Paul W Nov 13 '22 at 04:24