在非 Google Cloud 环境中设置 reCAPTCHA Enterprise
本快速入门介绍如何在支持外部身份验证方法(如服务帐号)的 Google Cloud、本地、CRM 或 SaaS 环境以外的云上设置 reCAPTCHA Enterprise。
在非 Google Cloud 环境中设置 reCAPTCHA Enterprise 需要启用 reCAPTCHA Enterprise API、创建服务账号以及为后端配置服务账号。
须知事项
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
控制台
在 Google Cloud 控制台中,转到 reCAPTCHA Enterprise API 页面。
验证项目名称是否显示在页面顶部的项目选择器中。
如果您没有看到项目名称,请点击项目选择器,然后选择您的项目。
- 点击启用。
gcloud
-
In the Google Cloud console, activate Cloud Shell.
At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
- 如需在 gcloud 会话中设置 Google Cloud 项目,请运行
gcloud config set project
命令。将 PROJECT_ID 替换为您的 Google Cloud 项目 ID。gcloud config set project PROJECT_ID
- 如需启用 reCAPTCHA Enterprise API,请运行
gcloud services enable
命令:gcloud services enable recaptchaenterprise.googleapis.com
- 如需验证 reCAPTCHA Enterprise API 是否已启用,请运行
gcloud services list
命令:gcloud services list --enabled
验证 reCAPTCHA Enterprise API 是否在已启用的 API 列表中列出。
配置服务帐号以进行后端身份验证
您可以使用 reCAPTCHA Enterprise 客户端库或 Google Cloud CLI 配置您为后端身份验证创建的新服务帐号。
客户端库
-
Provide authentication credentials to your application code by setting the environment variable
GOOGLE_APPLICATION_CREDENTIALS
. This variable applies only to your current shell session. If you want the variable to apply to future shell sessions, set the variable in your shell startup file, for example in the~/.bashrc
or~/.profile
file.Linux 或 macOS
export GOOGLE_APPLICATION_CREDENTIALS="
KEY_PATH
"Replace
KEY_PATH
with the path of the JSON file that contains your credentials.For example:
export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/service-account-file.json"
Windows
For PowerShell:
$env:GOOGLE_APPLICATION_CREDENTIALS="
KEY_PATH
"Replace
KEY_PATH
with the path of the JSON file that contains your credentials.For example:
$env:GOOGLE_APPLICATION_CREDENTIALS="C:\Users\username\Downloads\service-account-file.json"
For command prompt:
set GOOGLE_APPLICATION_CREDENTIALS=
KEY_PATH
Replace
KEY_PATH
with the path of the JSON file that contains your credentials. - 安装客户端库。
C#
如需了解详情,请参阅设置 C# 开发环境。Install-Package Google.Cloud.RecaptchaEnterprise.V1
Go
如需了解详情,请参阅设置 Go 开发环境。go get cloud.google.com/go/recaptchaenterprise/apiv1
Java
如需了解详情,请参阅设置 Java 开发环境。If you are using Maven, add the following to your
pom.xml
file. For more information about BOMs, see The Google Cloud Platform Libraries BOM.If you are using Gradle, add the following to your dependencies:
If you are using sbt, add the following to your dependencies:
If you're using Visual Studio Code, IntelliJ, or Eclipse, you can add client libraries to your project using the following IDE plugins:
The plugins provide additional functionality, such as key management for service accounts. Refer to each plugin's documentation for details.
Node.js
如需了解详情,请参阅设置 Node.js 开发环境。npm install --save @google-cloud/recaptcha-enterprise
PHP
如需了解详情,请参阅在 Google Cloud 上使用 PHP。将该库作为依赖项添加到您的composer.json
文件中:composer require google/cloud-recaptcha-enterprise
或者,您也可以在本地下载软件包。Python
如需了解详情,请参阅设置 Python 开发环境。pip install --upgrade google-cloud-recaptcha-enterprise
Ruby
如需了解详情,请参阅设置 Ruby 开发环境。gem install google-cloud-recaptcha_enterprise
现在,您创建的服务账号可以用于后端身份验证。创建评估时,您可以使用 reCAPTCHA Enterprise 客户端库对服务账号进行身份验证。
gcloud CLI
-
Install the Google Cloud CLI, then initialize it by running the following command:
gcloud init
-
Provide authentication credentials to your application code by setting the environment variable
GOOGLE_APPLICATION_CREDENTIALS
. This variable applies only to your current shell session. If you want the variable to apply to future shell sessions, set the variable in your shell startup file, for example in the~/.bashrc
or~/.profile
file.Linux 或 macOS
export GOOGLE_APPLICATION_CREDENTIALS="
KEY_PATH
"Replace
KEY_PATH
with the path of the JSON file that contains your credentials.For example:
export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/service-account-file.json"
Windows
For PowerShell:
$env:GOOGLE_APPLICATION_CREDENTIALS="
KEY_PATH
"Replace
KEY_PATH
with the path of the JSON file that contains your credentials.For example:
$env:GOOGLE_APPLICATION_CREDENTIALS="C:\Users\username\Downloads\service-account-file.json"
For command prompt:
set GOOGLE_APPLICATION_CREDENTIALS=
KEY_PATH
Replace
KEY_PATH
with the path of the JSON file that contains your credentials.
现在,您创建的服务账号可以用于后端身份验证。创建评估时,您可以使用 gcloud CLI 对服务帐号进行身份验证。
后续步骤
- 确定要使用的 reCAPTCHA(网站)密钥的类型并创建 reCAPTCHA 密钥。
-
或
将 reCAPTCHA Enterprise 与 Android 应用或 iOS 应用集成。
创建评估。
解读评估,并根据得分对您的网站采取适当的措施。