Published
8/19/2024
Categories
Web Development

Setting Up Google reCaptcha Enterprise

From reCaptcha documentation

If you're thinking of integrating reCaptcha onto your website or need help understanding how to set permissions on Google, follow this step-by-step guide to ensure a smooth setup process. 

Preface

Typically the need for reCaptcha occurs because a site may have a public facing form that anonymous users can submit and typically a site will want to avoid malicious attacks, spams, and overload of the system. The best way to combat this is using reCaptcha. ReCaptcha is used to verify that the user is in fact a human user attempting to submit only necessary requests to a site. There are options to add reCaptcha to a site but one of the most popular is Google reCaptcha. Google reCaptcha Enterprise offers much of the same functionality as the lower tiers and with a few more benefits for a larger scale site. 

Prerequisites

  1. Google Cloud Account: Ensure you have a Google Cloud account with an active project/application.

  2. Environment Configuration: You'll need to add your application's name to your environment configuration file (.env) using the key GOOGLE_APPLICATION_NAME.

Configuring reCaptcha

  1. Domain Setup:

    • You can edit the reCaptcha key to include the domain of the website that will be using this key.

    • Alternatively, you can select the "Disable domain verification" option.

  2. Enabling reCaptcha Enterprise:

    • In your Google Cloud Console, navigate to Detections and Controls.

    • Enable reCaptcha Enterprise and generate a reCaptcha Key.

    • Add this reCaptcha site key to your .env file as GOOGLE_RECAPTCHA_SITE_KEY.

Creating and Configuring a Service Account

  1. Service Account Creation:

    • Go to the IAM & Admin section in your Google Cloud Console.

    • Create a new service account.

  2. Assigning Permissions:

    • After creating the service account, navigate to the Roles and permissions section.

    • Grant the “roles/recaptchaenterprise.agent” role to the service account.

    • Click on "Grant Access" and add the newly created role.

    • Ensure you add the current user email/username in the "new principals" field before saving.

  3. Generating and Downloading Credentials:

    • Navigate to Service Accounts in your Google Cloud Console.

    • Click on the service account you created.

    • Go to the Keys section and click on "Add Key" -> "Create Key".

    • Select the "JSON" format and click "Create". This will download the JSON credential file.

Final Setup

  1. Storing Credentials:

    • Place the downloaded JSON file in a secure location on your file system. Important: Do not commit this file to your version control repository.

  2. Configuring Environment File:

    • Locate the absolute path of the JSON file on your system.

    • Add this path to your .env file using the key GOOGLE_APPLICATION_CREDENTIALS.

By following these steps, you will have successfully set up Google reCaptcha Enterprise for your Wholesale Application system, ensuring a robust and secure user experience.