recaptcha enterprise is just crazy hard

Sorry, I can't even figure out where to post questions for Google reCaptcha Enterprise.  Please direct this where it should be. Thanks.

I am trying to implement Google reCaptcha Enterprise. I am not new to coding but this is killing me. I program in C#, VB, JavaScript, .NET and others.  I cannot get a simple Test page to work and validate a checkbox.

I would give you an example and errors, but I have tried 20 different ways. The closest I got was a 403 error on the assessment call.  I tried the .NET library, which looked VERY promising until I ran it and got an error about needing an environment Variable GOOGLE_APPLICATION_CREDENTIALS pointing to a file that I can find NO documentation on. What goes in it?

It should be simple. I have jumped through the hoops, created a project, enabled the Enterprise API, I created an API key, granted access to localhost and my test domain. 

Can someone show me a SIMPLE sample that presents a checkbox and successfully accesses the result from the server using C# or VB with or without the .NET library?

At this point I wish I had just used my time to create my own captcha.

Thanks you for your time.

Sean

 

4 12 1,438
12 REPLIES 12

hey sean I'm a reCAPTCHA engineer, I don't have any super simple examples handy and I also don't know too much about the backend integration. It sounds like a lot of what you're confused with (creating the project, GOOGLE_APPLICATION_CREDENTIALS) etc is more google cloudy stuff than reCAPTCHA-specific stuff. I do know however that we made a pretty cool demo thing that might help, it spins up an example frontend and backend for you to look at.  Also have you seen this bad boy ? Example create assessment in C# included.

Also just so we're on the same page, the checkbox (or actually v3 is recommended) should be on the page served to the user in your frontend in JS, right? and then you send the token result to your server, which has in the enviroment some magic cloud stuff probably, and you createAssessment to get the score there?

 

I really recommend you try the demo site thingy, my coworker who sits behind me spent a lot of time making it really cool 😄

Hi Matt,
Thank you for your response.
I have seen the "bad boy" you referenced, but that asks for a google credentials file I can find no documentation on so I cannot create it.

I am generating the checkbox on the front end just fine. It is submitting the token to my backend just fine. I am NOT running on Google Cloud, but on my client's Web Server. That has caused some difficulties.

I will look at the demo and see if I can adapt it to my C#.Net backend. I will update you when I can.
Thanks again,
Sean

Nice! When you say "that asks for a google credentials file", do you mean you receive an error response from the createAssessment call to that effect? Maybe a sample of that error would be helpful to debug.

The front end is fine and it passes the token to the backend.

The error I get in the "bad boy" code is where the backend code tries to create RecaptchaEnterpriseServiceClient. Th error says the Application Default Credentials are not available ....

recaptcha_error.jpg

I hope that is readable.

 

Hi Sean! One of the Customer Engineering Specialists on reCAPTCHA Enterprise here, and happy to help.

This message is referring to the Application Default Credentials. You can learn more about it here, and then follow the flow here. From a high-level, you have two options:

  • Create a Service Account and download the JSON file as outlined here. After, set your environmental variable GOOGLE_APPLICATION_CREDENTIALS to point to the JSON file.
  • Set your Application Default Credentials (ADC) by using gcloud CLI and then issue the gcloud auth application-default login command. More info here

I agree with Shawn, it's just absolutely nuts how hard it is to use Recaptcha v3. After implementing it with both Keys (client and server keys) we found out the PHP SDK fails hard and brutal with error "Could not construct ApplicationDefaultCredentials ". Days of research later we found out how to set up the Google CLI (why is this not properly said in the first place) that somehow creates a weird file somewhere, that is somehow used to authenticate. But then why the heck we have the both keys in the first place? We also couldn't find out how to tell the SDK to use this file, as it is not documented. Who made this ? Who tested this? Who thinks this is a valid customer experience? It feels like Recaptcha v3 was set up by people who have no clue how software is built.

Days of days of work to get less then 10 lines of code working, absolutely insane.

Hey Chris,

Thanks for posting. I am a long time programmer and I was afraid I was losing my touch!  So glad it's not just me.

I am thrilled to see that I need to setup Google CLI to get this mystery file.

I am VERY disappointed that not even the "reCAPTCHA engineer" can post a simple working example - in any language.

Once I get this file, and a little time to do  Google's job, I hope to post a working example.

Sean

Hah, yikes. So again this seems to be more a google cloud than a recaptcha specific question, in that the thing it's asking is some cloud authentication stuff. I think the docs that Josh linked are pretty clear. I don't think a "working example" would really be helpful, since it's just a command you run to make the file, right? Check out the docs there.

Speaking to the code snippet you posted there Sean, I think that looks good to me 😄

Thanks,

Matt

HI Chris,

That worked!  I installed gcloud cli and ran init. then I ran:
gcloud auth application-default login

It responded with:
Credentials saved to file: [C:\Users\Sean\AppData\Roaming\gcloud\application_default_credentials.json]

I set the environment variable GOOGLE_APPLICATION_CREDENTIALS to that filename and poof it worked.

I am using the .net  library sample code, so first thing, I added:
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", "C:\Users\Sean\AppData\Roaming\gcloud\application_default_credentials.json")

I don't have a clue how that would work in the JavaScript version. It clearly has no access to that file.

Once you have created your recaptcha key. click the overview button on its "card". Look at the  integration tab. I used the C# code under "Send tokens and get scores (Backend)"

Agree with topic title. Struggling entire day to implement this and end up here. I need simple recaptcha on my website and you force me to do some cloud stuff that I have no idea about and I dont really want. What am I authenticating? Why do I need this? None of old tutorials found on the internet is working because of this missing environmental variable error. 
I've set up gcloud, created this json file, uploaded on my hosting and created environmental variable GOOGLE_APPLICATION_CREDENTIALS pointing to this json file. Still not working and have no idea how to move on

Hi joenamst,

What error are you getting? As an alternative, you can always use an API key instead, and entirely skip all of the Client Library, Service Account, and JSON handling steps. To do that, see this doc for creating an API key and remember to secure it to your specific IPs and the reCAPTCHA Enterprise API.

Once you have the API key, follow the "Use an API key" instructions under here. This is a simpler process for many of our customers!

Hi joenamst,

I posted the resolution, but that post is not here now.

The problem is NOT the API itself. The whole problem is the DOT NET library.  It is that library that requires the credential file and the  GOOGLE_APPLICATION_CREDENTIALS environment variable. Nothing in that credential file is needed for the maps api.

PM me if you want my sample of doing it without the library (C# or VB).

Sean