Instalar chaves de desafio com base em políticas em sites
Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Nesta página, explicamos como instalar uma chave de teste baseada em política no seu site.
Com uma chave de desafio baseada em política, o reCAPTCHA pode acionar de forma determinística
testes de CAPTCHA com base em um limite de pontuação e na dificuldade do teste.
Configurar a chave do desafio com base em políticas
Para sua chave de desafio baseada em política, especifique a dificuldade do desafio
que determina a complexidade e a frequência dos testes de CAPTCHA e
defina um limite de pontuação personalizado para ações específicas que substitui o limite
padrão.
No console Google Cloud , acesse a página reCAPTCHA.
A página reCAPTCHA tem duas visualizações: Tabelas e Cards.
Se o projeto tiver muitas chaves reCAPTCHA, apenas a visualização Tabela estará disponível.
Verifique se o nome do projeto aparece no seletor de recursos, na
parte superior da página.
Se você não vir o nome do projeto, clique no seletor de recursos
e selecione seu projeto.
Na seção Chaves reCAPTCHA, identifique a chave de desafio baseada em política
que você quer configurar e clique nela.
Na página Detalhes da chave, acesse a guia Visão geral.
Na seção Configuração, clique em Configurar para Configurações de desafio.
Na página Definir configurações do desafio, selecione a dificuldade do desafio.
Para acionar testes de CAPTCHA, use o controle deslizante para especificar o valor padrão do limite.
O limite padrão de 0.0 não aciona nenhum desafio. O 1.0
aciona um desafio para cada solicitação.
Para configurar um limite de pontuação personalizado para ações individuais, que substitui o valor limite padrão, faça o seguinte:
Para especificar um limite de pontuação personalizado, use o controle deslizante Definir limite de ação.
Clique em Concluído.
Clique em Salvar.
Adicionar o reCAPTCHA a um botão HTML
Para carregar o reCAPTCHA na página da Web, adicione a API JavaScript com
a chave de desafio baseada em política no elemento <head></head>
da página da Web.
O reCAPTCHA usa o idioma do navegador por padrão. Se você quiser
especificar um idioma diferente, use o atributo hl=LANG
no script.
Por exemplo, para usar o francês, especifique o seguinte:
<script src="https://www.google.com/recaptcha/enterprise.js?hl=fr"></script>.
Para saber mais sobre os idiomas aceitos, consulte
códigos de idioma do reCAPTCHA.
Para adicionar o reCAPTCHA a um botão HTML simples, faça o
seguinte:
Defina uma função de callback para manipular o token.
<script>
function onSubmit(token) {
document.getElementById("demo-form").submit();
} // Use `requestSubmit()` for extra features like browser input validation.
</script>
Se você quiser especificar um local para o selo, use o atributo data-badge=LOCATION
no elemento que tem class=g-recaptcha. Por padrão, o local é definido como bottomright.
Os outros valores possíveis são inline e bottomleft.
Quando esse botão é usado para enviar um formulário no site, o parâmetro POST
g-recaptcha-response contém o token de resposta.
Depois que o token for gerado, envie-o
para o back-end e crie uma avaliação em dois minutos.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-09-04 UTC."],[],[],null,["# Install policy-based challenge keys on websites\n\n| This feature is subject to the \"Pre-GA Offerings Terms\" in the General Service Terms section\n| of the [Service Specific Terms](/terms/service-terms#1).\n|\n| Pre-GA features are available \"as is\" and might have limited support.\n|\n| For more information, see the\n| [launch stage descriptions](/products#product-launch-stages).\n\nThis page explains how to install a policy-based challenge key on your website.\nWith a policy-based challenge key, reCAPTCHA can deterministically\ntrigger CAPTCHA challenges based on a score threshold and challenge difficulty.\n\nBefore you begin\n----------------\n\n1.\n\n [Prepare your environment for reCAPTCHA](/recaptcha/docs/prepare-environment).\n\n2. [Create a policy-based challenge key](/recaptcha/docs/create-key-website).\n\n Alternatively, you can copy the ID of an existing policy-based challenge key by\n performing one of the following steps:\n\n\n - To copy the ID of an existing key from the **Google Cloud console**,\n do the following:\n\n 1. Go to the **reCAPTCHA** page.\n\n [Go to reCAPTCHA](https://console.cloud.google.com/security/recaptcha)\n 2. In the reCAPTCHA keys list, hold the pointer over the key you want to copy, and then click content_copy .\n - To copy the ID of an existing key using the **REST API** , use the [projects.keys.list](/recaptcha/docs/reference/rest/v1/projects.keys/list) method.\n - To copy the ID of an existing key using the **gcloud CLI** , use the [gcloud recaptcha keys list](/sdk/gcloud/reference/recaptcha/keys/list) command.\n\n \u003cbr /\u003e\n\nConfigure the policy-based challenge key\n----------------------------------------\n\nFor your policy-based challenge key, you must specify the challenge difficulty\nthat determines the complexity and frequency of CAPTCHA challenges, and\ndefine a custom score threshold for specific actions that overrides the default\nthreshold.\n\n1. In the Google Cloud console, go to the **reCAPTCHA** page.\n\n [Go to reCAPTCHA](https://console.cloud.google.com/security/recaptcha)\n\n The **reCAPTCHA** page has two views: **Tables** and **Cards** .\n If your project has many reCAPTCHA keys, only the **Table** view is available.\n2. Verify that the name of your project appears in the resource selector\n at the top of the page.\n\n If you don't see the name of your project, click the resource selector,\n and then select your project.\n3. In the **reCAPTCHA keys** section, identify the policy-based challenge key\n that you want to configure, and click the key.\n\n4. In the **Key details** page, go to the **Overview tab**.\n\n5. In the **Configuration** section, click **Configure** for **Challenge settings**.\n\n6. In the **Configure challenge settings** page, select the challenge difficulty.\n\n7. To trigger CAPTCHA challenges, use the slider to specify the default\n threshold value.\n\n The default threshold of `0.0` does not trigger any challenge. `1.0`\n triggers a challenge for every request.\n8. To configure a custom score threshold for individual actions, which overrides\n the default threshold value, do the following:\n\n 1. Enter an [action name](/recaptcha/docs/actions-website).\n\n | **Note:** You cannot use more than 100 action names.\n 2. To specify a custom score threshold, use the **Set action threshold**\n slider.\n\n 3. Click **Done**.\n\n9. Click **Save**.\n\nAdd reCAPTCHA on an HTML button\n-------------------------------\n\n1.\n\n To load reCAPTCHA on your web page, add the JavaScript API with\n your policy-based challenge key within the `\u003chead\u003e\u003c/head\u003e`\n element of your web page.\n\n \u003cbr /\u003e\n\n ```scdoc\n \u003chead\u003e\n \u003cscript src=\"https://www.google.com/recaptcha/enterprise.js?render=KEY_ID\"\u003e\u003c/script\u003e\n ....\n \u003c/head\u003e\n \n ```\n\n \u003cbr /\u003e\n\n reCAPTCHA uses the browser's language by default. If you want to\n specify a different language, use the `hl=`\u003cvar translate=\"no\"\u003eLANG\u003c/var\u003e attribute\n in your script.\n For example, to use French, specify the following:\n `\u003cscript src=\"https://www.google.com/recaptcha/enterprise.js?hl=fr\"\u003e\u003c/script\u003e`.\n To learn about the supported languages, see\n [language codes for reCAPTCHA](/recaptcha/docs/language).\n\n \u003cbr /\u003e\n\n2. To add reCAPTCHA on a simple HTML button, do the\n following:\n\n 1. Define a callback function to handle the token.\n\n ```text\n \u003cscript\u003e\n function onSubmit(token) {\n document.getElementById(\"demo-form\").submit();\n } // Use `requestSubmit()` for extra features like browser input validation.\n \u003c/script\u003e\n ```\n\n For more information, see [requestSubmit() method](https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/requestSubmit).\n 2. Add attributes to your html button.\n\n ```scdoc\n \u003cbutton class=\"g-recaptcha\"\n data-sitekey=\"KEY_ID\"\n data-callback=\"onSubmit\"\n data-action=\"submit\"\u003eSubmit\u003c/button\u003e\n ```\n\n If you want to specify a location for the badge, then use the `data-badge=`\u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e\n attribute on the element that has `class=g-recaptcha`. By default, the location is set to `bottomright`.\n The other possible values are `inline` and `bottomleft`.\n 3. When this button is used to submit a form on your site, the\n `g-recaptcha-response` POST parameter contains the response token.\n\n | **Note:** If you set the `g-recaptcha` button as `disabled`, the button is enabled when reCAPTCHA is loaded.\n3.\n\n After the token is generated, send the reCAPTCHA token\n to your backend and create an assessment within two minutes.\n | **Important:** The `action` that you specify is returned as part of the assessment. You must verify that the `action` in the JSON response of the assessment matches the expected action that you specify when creating an assessment. For example, a `login` action should be returned on your **login** page. If there is a mismatch, it indicates that an attacker is attempting to falsify actions.\n\n \u003cbr /\u003e\n\nWhat's next\n-----------\n\n- To assess the reCAPTCHA response token, [create an assessment](/recaptcha/docs/create-assessment-website)."]]