Google reCAPTCHA: how to generate captcha token on the server side

Viewed 1765

I've added the Google reCAPTCHA enterprise to my auth endpoints, and now I want to cover them by integration tests. To do so, I need to generate a valid token and pass it to requests. But I can't find in the docs how to do that, they only offer to create a separate reCAPTCHA key for testing environment which is not suitable for me, because I want to test production too.

2 Answers

I am not sure if I understood you, but I utilized test keys for testing Recaptcha using Cypress , here you can find them and more information about what you want

Copied from some source

Hello,

If you’re getting new reCaptcha keys each time you create a site then I’m afraid to say you’re doing so improperly for this scenario. Hopefully, the below instructions can help:

  1. Log into your Google Admin Console.

  2. Browse to the API key that you have set for your website. If you have more than 1 reCaptcha in your Admin Console you may need to click the dropdown next to the “You have ‘x’ site(s)”.

  3. Once you’ve found your specific reCaptcha API, you’ll want to click the Settings gear icon at the top right. This will bring you to your API settings where you can grab your reCaptcha keys and add additional domains to the allow-list.

  4. On the Settings screen you should see a list of domains in an allow-list with an input box to enter additional domains. There should be a plus sign next to this input box. Enter your domain and click the plus sign.

  5. Finally, scroll to the bottom of the page and click the blue “Save” button. This will tell Google to apply your changes and may take up to 5 minutes to be put into place.

This will tell Google to allow the same reCaptcha keys for multiple domains specified in this allow-list on the Settings page. For further help, we’ve created an Imgur Album of a few screenshots that may help you along your way:

https://imgur.com/a/aT8J6Uu

Hopefully, with the above instructions, you’ll be able to add in your additional domains to the allow list. Should you need further assistance, we suggest reaching out to Google G Suite Admin Support.

Hope it will solve your issue

If it still didn't work in your scenario you can use the dynamic way of applying keys like saving keys into the Environment variable and based on the current environment it will be changed dynamically

Related