As chaves de API são associadas ao projeto Google Cloud em que
foram criadas. Se a API exigir uma chave de API, você terá que fornecer aos usuários da API uma chave do projeto em que criou o serviço Cloud Endpoints ou permitir que eles ativem a API nos próprios projetos do Google Cloude criem uma chave de API. Nesta página, mostraremos como conceder a permissão de que os usuários precisam para ativar a API.
conceder acesso
O Endpoints usa o papel
Identity and Access Management (IAM)Consumidor de serviço para permitir que alguém que não seja membro do projeto
Google Cloud possa ativar a API no projeto Google Cloud
próprio. Esta seção mostra como conceder acesso usando o
consoleGoogle Cloud ou a CLI do Google Cloud.
Console doGoogle Cloud
No Google Cloud console, acesse a página Endpoints > Services
do seu projeto.
Se você tiver mais de uma API, clique no nome da API à qual você quer
conceder acesso.
Se o painel lateral Permissões não estiver aberto, clique em Mostrar painel de permissões.
No campo Adicionar principal, insira o endereço de e-mail da pessoa ou do
Grupo do Google a que
você quer conceder acesso.
No menu suspenso Selecionar um papel, escolha Gerenciamento de serviço >
Consumidor do serviço.
Clique em Salvar.
Adicione quantos membros e papéis forem necessários.
Entre em contato com os usuários ou grupos que você adicionou e informe que eles podem
ativar a API nos próprios projetos do Google Cloud . Consulte
Ativar uma API no seu projeto do Google Cloud para informações sobre como ativar um serviço em APIs e serviços.
gcloud
Abra o Cloud Shell ou, se você tiver a CLI do Google Cloud instalada, abra
uma janela de terminal.
Se você está concedendo acesso a um usuário individual:
Entre em contato com os usuários ou grupos que você adicionou e informe que eles podem ativar
a API nos próprios projetos do Google Cloud . Consulte
Ativar uma API no seu projeto do Google Cloud para informações sobre como ativar um serviço nas APIs e serviços.
Como revogar o acesso
Para revogar o acesso à API, remova o papel Consumidor de serviços de um usuário ou grupo que antes tinha essa função. Com o acesso revogado,
o usuário ou grupo não poderá ativar sua API.
Esta seção mostra como revogar o acesso usando o console Google Cloud ou
a CLI do Google Cloud.
Console doGoogle Cloud
No Google Cloud console, acesse a página Endpoints > Services
do Google Cloud seu projeto.
[[["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."],[[["\u003cp\u003eAPI keys are linked to the Google Cloud project where they are created, allowing users to utilize keys from the service's project or enable the API in their own project.\u003c/p\u003e\n"],["\u003cp\u003eThe Identity and Access Management (IAM) Service Consumer role grants external users the ability to enable the API in their Google Cloud projects.\u003c/p\u003e\n"],["\u003cp\u003eAccess can be granted to users or Google Groups via the Google Cloud console or the Google Cloud CLI by assigning the Service Consumer role.\u003c/p\u003e\n"],["\u003cp\u003eAccess can be revoked from users or Google Groups through the Google Cloud console or the Google Cloud CLI by removing the Service Consumer role.\u003c/p\u003e\n"],["\u003cp\u003eRevoking access doesn't prevent users who have already enabled the API from making calls, however, logic can be implemented to disable specific API keys.\u003c/p\u003e\n"]]],[],null,["# Controlling who can enable your API\n\nOpenAPI \\| [gRPC](/endpoints/docs/grpc/control-api-callers \"View this page for the Cloud Endpoints gRPC docs\")\n\n\u003cbr /\u003e\n\nAPI keys are associated with the Google Cloud project in which\nthey have been created. If your API requires an API key, you either have to give\nyour API users a key from the project that you created the Cloud Endpoints\nservice in, or you can let users enable your API in their own Google Cloud\nproject and create an API key. This page shows you how to grant the permission\nthat users need to enable your API.\n\nGranting access\n---------------\n\nEndpoints uses the\n[Identity and Access Management (IAM)](/iam/docs)\n**Service Consumer** role to allow someone who isn't a member of your\nGoogle Cloud project to enable your API in their own Google Cloud\nproject. This section shows you how to grant access using the\nGoogle Cloud console or the Google Cloud CLI. \n\n### Google Cloud console\n\n1. In the Google Cloud console, go to the **Endpoints** \\\u003e **Services** page for your project.\n\n\n [Go to the Endpoints Services page](https://console.cloud.google.com/endpoints)\n\n \u003cbr /\u003e\n\n2. If you have more than one API, click the name of the API that you want to grant access to.\n3. If the **Permissions** side panel isn't open, click **Show Permissions Panel**.\n4. In the **Add Principal** field, enter the email address of the person or [Google Group](https://support.google.com/groups/answer/2464926) that you want to grant access to.\n5. In the **Select a role** drop-down menu, select **Service Management** \\\u003e **Service Consumer**.\n6. Click **Save**.\n7. Repeat adding members and selecting the role, as needed.\n8. Contact the users or groups that you added and let them know they can enable the API in their Google Cloud projects. See [Enable an API in your Google Cloud\n project](/endpoints/docs/openapi/enable-api) for information on how to enable a service in APIs \\& services.\n\n### gcloud\n\n1. Open Cloud Shell, or if you have the Google Cloud CLI installed, open a terminal window.\n - If you are granting access to an individual user:\n\n - If you are granting access to a Google Group:\n\n2. Contact the users or groups that you added and let them know they can enable the API in their Google Cloud projects. See [Enable an API in your Google Cloud\n project](/endpoints/docs/openapi/enable-api) for information on how to enable a service in APIs \\& services.\n\nRevoking access\n---------------\n\nYou revoke access to your API by removing the **Service Consumer** role from a\nuser or group that previously had the role. After you revoke someone's access,\nthey won't be able to enable your API.\n| **Note:** If someone has already enabled your API, revoking access doesn't prevent them from calling your API. Although there is no easy way to to prevent these calls, you can add logic to your code that disallows calls from a specific caller's API key.\n\nThis section shows you how to revoke access using the Google Cloud console or\nthe Google Cloud CLI. \n\n### Google Cloud console\n\n1. In the Google Cloud console, go to the **Endpoints** \\\u003e **Services** page for your Google Cloud project.\n\n\n [Go to the Endpoints Services page](https://console.cloud.google.com/endpoints)\n\n \u003cbr /\u003e\n\n2. If you have more than one API, click the name of the API that you want to revoke access to.\n3. If the **Permissions** side panel isn't open, click **addPermissions**.\n4. Click the **Role** card that the member belongs to.\n5. Click **Delete** delete.\n\n### gcloud\n\n- If you are revoking access for an individual user:\n\n- If you are revoking access for a Google Group:\n\nWhat's next\n-----------\n\n- Tell users how to [enable your API in their Google Cloud project](/endpoints/docs/openapi/enable-api).\n\n\u003c!-- --\u003e\n\n- Learn more about [Sharing APIs protected by API keys](/endpoints/docs/openapi/restricting-api-access-with-api-keys#sharing_apis_protected_by_api_key).\n\n\u003c!-- --\u003e\n\n- Create a [Cloud Endpoints Portal](/endpoints/docs/openapi/dev-portal-overview) for your users."]]