|
| 1 | +# Google Cloud reCAPTCHA Enterprise |
| 2 | + |
| 3 | +Google [Cloud reCAPTCHA Enterprise](https://cloud.google.com/recaptcha-enterprise) helps protect your website from fraudulent activity, spam, and abuse without creating friction. |
| 4 | + |
| 5 | +# Google Cloud reCAPTCHA Enterprise |
| 6 | + |
| 7 | +## Prerequisites |
| 8 | + |
| 9 | +### Google Cloud Project |
| 10 | + |
| 11 | +Set up a Google Cloud project. |
| 12 | +Billing information is **not needed** to deploy this application. |
| 13 | + |
| 14 | +# One-click deploy |
| 15 | + |
| 16 | +1. Click the below "Open in Cloud Shell" button. |
| 17 | + |
| 18 | +<a href="https://shell.cloud.google.com/cloudshell/editor?cloudshell_git_repo=https://github.com/googleapis/nodejs-recaptcha-enterprise&cloudshell_git_branch=demosite"> |
| 19 | +<img alt="Open Cloud Shell" src ="http://gstatic.com/cloudssh/images/open-btn.png"></a> |
| 20 | + |
| 21 | +2. Run |
| 22 | +``` |
| 23 | +cd samples/demosite/app && sh init.sh |
| 24 | +``` |
| 25 | + |
| 26 | +3. Click on the localhost link in the terminal output. You'll find the deployed application. |
| 27 | + |
| 28 | + |
| 29 | +# Manual Deploy |
| 30 | + |
| 31 | +### 1. Enable the reCAPTCHA Enterprise API |
| 32 | + |
| 33 | +You must [enable the Google reCAPTCHA Enterprise API](https://console.cloud.google.com/flows/enableapi?apiid=recaptchaenterprise.googleapis.com) for your project in order to use this application. |
| 34 | + |
| 35 | +### 2. Create Score key and Checkbox key |
| 36 | + |
| 37 | +Create a Score key, and a Checkbox key via [Cloud Console.](https://console.cloud.google.com/security/recaptcha) |
| 38 | + |
| 39 | +### 3. Set Environment Variables |
| 40 | + |
| 41 | +Open the CloudShell from Cloud Console. |
| 42 | +Set your project ID and site keys. |
| 43 | + |
| 44 | +```angular2html |
| 45 | +export GOOGLE_CLOUD_PROJECT="<google-project-id-here>" |
| 46 | +export SITE_KEY="<score-key-id-here>" |
| 47 | +export CHECKBOX_SITE_KEY="<checkbox-key-id-here>" |
| 48 | +``` |
| 49 | + |
| 50 | +### 4. Clone, Build and Run |
| 51 | + |
| 52 | +The following instructions will help you prepare your development environment. |
| 53 | + |
| 54 | + |
| 55 | +1. Clone the nodejs-recaptcha-enterprise repository and navigate to ```samples/demosite``` directory. |
| 56 | + |
| 57 | +``` |
| 58 | +cloudshell_open --repo_url "https://github.com/googleapis/nodejs-recaptcha-enterprise.git" --dir "samples/demosite" --page "shell" --force_new_clone --git_branch "demosite" |
| 59 | +``` |
| 60 | + |
| 61 | +2. Run docker-compose |
| 62 | + |
| 63 | +``` |
| 64 | +/usr/local/bin/docker-compose -f $PWD/docker-compose.yaml up --build |
| 65 | +``` |
| 66 | + |
| 67 | +3. Click on the localhost link in the terminal output. You'll find the deployed application. |
| 68 | + |
| 69 | +## Authentication |
| 70 | + |
| 71 | +The above _**one-click**_ and _**manual**_ deployment works with the default **compute-engine** service account in the project. |
| 72 | +If you want to create a new service account, follow the below steps. |
| 73 | + |
| 74 | +### 1. Create Service account |
| 75 | + |
| 76 | +A service account with private key credentials is required to create signed bearer tokens. |
| 77 | + |
| 78 | +Create |
| 79 | +1. [Service account](https://console.cloud.google.com/iam-admin/serviceaccounts/create) |
| 80 | +2. [Key](https://cloud.google.com/iam/docs/creating-managing-service-account-keys#iam-service-account-keys-create-console) for the service account |
| 81 | +3. Download the key credentials file as JSON. |
| 82 | + |
| 83 | +### 2. Grant Permissions |
| 84 | + |
| 85 | +You must ensure that the [user account or service account](https://cloud.google.com/iam/docs/service-accounts#differences_between_a_service_account_and_a_user_account) you used to authorize your gcloud session has the proper permissions to edit reCAPTCHA Enterprise resources for your project. In the Cloud Console under IAM, add the following roles to the project whose service account you're using to test: |
| 86 | + |
| 87 | +* reCAPTCHA Enterprise Agent |
| 88 | +* reCAPTCHA Enterprise Admin |
| 89 | + |
| 90 | +More information can be found in the [Google reCAPTCHA Enterprise Docs](https://cloud.google.com/recaptcha-enterprise/docs/access-control#rbac_iam). |
| 91 | + |
| 92 | +### 3. Export the Service account credentials |
| 93 | + |
| 94 | +```angular2html |
| 95 | +export GOOGLE_APPLICATION_CREDENTIALS="<path-to-service-account-credentials-file>" |
| 96 | +``` |
0 commit comments