Uma chave API (conhecida no Apigee como uma chave de consumidor) é um valor de string transmitido por uma app cliente aos seus proxies de API. A chave identifica de forma exclusiva a app cliente.
A validação da chave da API é a forma mais simples de segurança baseada em apps que pode configurar para uma API. Uma app cliente apresenta simplesmente uma chave da API com o seu pedido. Em seguida, o Apigee verifica se a chave da API se encontra num estado aprovado para o recurso que está a ser pedido. Internamente, os seus proxies usam políticas para validar a autenticidade da chave de API.
Para suportar esta simplicidade, tem de fazer alguma configuração. Para suportar chaves da API, tem de:
Crie um produto de API Apigee que agrupe os proxies de API que quer
proteger com a chave da API.
Crie uma app de programador do Apigee que represente o programador da app cliente
cuja app vai autenticar.
Ao criar a app do programador, especifica os produtos da API aos quais a app do programador terá
acesso e para os quais terá de fornecer uma chave da API.
Aos seus proxies (os que incluiu no seu produto de API), adicione políticas
para verificar se uma chave da API recebida é válida.
No Apigee, uma chave da API é denominada chave do consumidor. Quando regista apps de programador,
o Apigee gera uma chave e um segredo do consumidor. O Apigee armazena a chave do consumidor para validação futura. Cada chave de consumidor é única na organização. O programador da app incorpora a chave do consumidor na app cliente. A app cliente tem de apresentar a chave do consumidor para cada pedido.
Os serviços de API validam a chave do consumidor antes de permitir o pedido da app.
Passos de alto nível
Os passos seguintes descrevem como as chaves de API são usadas pelo Apigee. Estes passos também incluem a possível presença de segurança OAuth, uma vez que é frequentemente usada em conjunto com chaves de API.
Crie um produto da API que inclua proxies da API que devem ser protegidos
com a chave da API.
Regista uma app de programador na sua organização. Quando o Apigee
gera uma chave de consumidor e um segredo do consumidor.
Associe a app do programador a, pelo menos, um produto de API. É o produto que associa os caminhos dos recursos e os proxies de API à aprovação de chaves.
Em tempo de execução, quando a app cliente faz um pedido à sua API, a app cliente envia
a chave do consumidor quando faz o pedido. Na prática, a chave de consumidor pode ser
transmitida explicitamente ou pode ser referida implicitamente através de um token OAuth:
Quando a API usa a validação da chave de API, como através da implementação de uma política VerifyAPIKey, a app cliente tem de transmitir a chave do consumidor explicitamente.
Quando a API usa a validação de tokens OAuth, como através da implementação de uma política OAuthV2, a app cliente tem de transmitir um token derivado da chave do consumidor.
O proxy de API valida as credenciais do pedido através de uma política VerifyAPIKey ou uma política OAuthV2 com uma operação VerifyAccessToken. Se não incluir uma política de aplicação de credenciais no seu proxy de API, qualquer autor da chamada pode invocar com êxito as suas APIs. Para mais informações, consulte a
Política de
Validação da Chave da API.
Se estiver a usar a validação de tokens OAuth, implementou uma política OAuth para validar
e a app cliente passou um token OAuth:
O Apigee verifica se o token não expirou e, em seguida, procura a chave do consumidor
que foi usada para gerar o token.
Se estiver a usar uma chave de API, implementou uma política VerifyAPIKey e a app cliente
transmitiu a respetiva chave do consumidor:
O Apigee verifica a lista de produtos de API aos quais a chave do consumidor foi associada.
O Apigee verifica cada produto de API para ver se o proxy de API atual está incluído no produto de API e se o caminho do recurso atual (caminho do URL) está ativado no produto de API.
O Apigee também verifica se a chave do consumidor não expirou nem foi revogada, se a app não foi revogada e se o programador não está inativo.
Se todas estas condições forem verdadeiras, ou seja, o token não tiver expirado (se aplicável), a chave
do consumidor for válida e aprovada, a app for aprovada, o programador estiver ativo, o proxy
estiver disponível no produto e o recurso estiver disponível no produto, a validação
das credenciais é bem-sucedida.
[[["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-08-21 UTC."],[[["\u003cp\u003eAPI keys, also known as consumer keys, uniquely identify client apps in Apigee and are used for a simple form of app-based security.\u003c/p\u003e\n"],["\u003cp\u003eTo implement API key validation, you must create an API product bundling the desired API proxies and a developer app representing the client app to be authenticated.\u003c/p\u003e\n"],["\u003cp\u003eClient apps present the API key with each request, and Apigee proxies utilize policies to verify the key's authenticity and approved status.\u003c/p\u003e\n"],["\u003cp\u003eAt runtime, requests from client apps include the consumer key, either directly or via an OAuth token derived from the consumer key, which is then validated by the API Proxy.\u003c/p\u003e\n"],["\u003cp\u003eApigee verifies that the API key is associated with an appropriate API Product, not expired or revoked, and that the corresponding app and developer are active, as well as that the requested resource is available.\u003c/p\u003e\n"]]],[],null,["# API keys\n\n*This page\napplies to **Apigee** and **Apigee hybrid**.*\n\n\n*View [Apigee Edge](https://docs.apigee.com/api-platform/get-started/what-apigee-edge) documentation.*\n\nAn *API key* (known in Apigee as a *consumer key*) is a string value passed\nby a client app to your API proxies. The key uniquely identifies the client app.\n\nAPI key validation is the simplest form of app-based security that you can configure for an\nAPI. A client app simply presents an API key with its request, then Apigee checks to see\nthat the API key is in an approved state for the resource being requested. Internally, your\nproxies use policies to verify API key authenticity.\n\nTo support this simplicity, you'll need to do a bit of setup. To support API keys, you'll need\nto:\n\n- **Create an Apigee API product** that bundles the API proxies you want to protect using the API key.\n- **Create an Apigee developer app** that represents the client app developer whose app you'll be authenticating.\n\n In creating the developer app, you specify API products the developer's app will have\n access to -- and for which it will need to provide an API key.\n- To your proxies (the ones you included in your API product), **add policies** to verify that an incoming API key is valid.\n\nThe [Secure an API by\nrequiring API keys](/apigee/docs/api-platform/tutorials/secure-calls-your-api-through-api-key-validation) tutorial is a quick way to learn how to control access to an API proxy\nwith an API key.\n| **Note:** The security associated with API keys is limited. Because API keys can easily be extracted from app code and used to access an API, they work better as unique app identifiers, rather than security tokens. If you're looking for a way to implement security, be sure to see [OAuth home](/apigee/docs/api-platform/security/oauth/oauth-home).\n| **Note:** API keys go by many names. You may see them referred to as app keys, developer app keys, consumer keys, or client IDs.\n| **Sample:** A working sample API proxy that enforces API key validation is available in the [API Platform\n| Samples](https://github.com/apigee/api-platform-samples) available on GitHub. You can use the sample API proxy to secure your own API. Locate the API proxy found under `/sample-proxies/apikey`. Modify the TargetEndpoint configuration to point to your URL. Then deploy.\n\nHow API keys work\n-----------------\n\nIn Apigee, an API key is referred to as a consumer key. When you register developer apps,\nApigee generates a consumer key and secret. Apigee stores the consumer key for future\nvalidation. Each consumer key is unique in the organization. The app developer embeds the\nconsumer key in the client app. The client app must present the consumer key for each request.\nAPI Services verifies the consumer key before permitting the app's request.\n\n### High-level steps\n\nThe following steps describe how API keys are used by Apigee. These steps include the\npossible presence of OAuth security as well, since it is often used in conjunction with API\nkeys.\n\n1. **Create an API product** that includes API proxies that should be protected with the API key.\n2. You **register a developer app** in your organization. When you do Apigee generates a consumer key and a consumer secret.\n3. **Associate the developer app with at least one API product**. It is the product that associates resource paths and API proxies with key approval.\n4. At run time, when the client app makes a request to your API, the **client app sends\n the consumer key when making the request** . In practice, the consumer key might be either passed explicitly or it might be implicitly referred to via an OAuth token:\n - When the API uses API key verification -- such as by implementing a VerifyAPIKey policy -- the client app must pass the consumer key explicitly.\n - When the API uses OAuth token verification -- such as by implementing an OAuthV2 policy -- the client app must pass a token that has been *derived from* the consumer key.\n5. The **API Proxy validates the request** credentials through either a VerifyAPIKey policy or an OAuthV2 policy with a VerifyAccessToken operation. If you do not include a credential enforcement policy in your API Proxy, any caller can successfully invoke your APIs. For more information, see [Verify API Key\n policy](/apigee/docs/api-platform/reference/policies/verify-api-key-policy).\n\n### Verifying request credentials\n\nThis is an overview. Be sure to see\n[Setting up API key\nvalidation](/apigee/docs/api-platform/security/setting-api-key-validation) for\ndetails and code examples.\n\n1. If you're using OAuth token verification -- you've implemented an OAuth policy to verify and the client app has passed an OAuth token:\n - Apigee verifies that the token is not expired, and then looks up the consumer key that was used to generate the token.\n2. If you're using an API key -- you've implemented a VerifyAPIKey policy and the client app has passed its consumer key:\n 1. Apigee checks the list of API Products with which the consumer key has been associated.\n 2. Apigee checks each API Product to see if the current API Proxy is included in the API Product, and if the current resource path (url path) is enabled on the API Product.\n 3. Apigee also verifies that the consumer key is not expired or revoked, checks that the app is not revoked, and checks that the developer is not inactive.\n 4. If all of those things are true -- the token is not expired (if applicable), the consumer key is valid and approved, the app is approved, the developer is active, the proxy is available in the product, and the resource is available on the product -- the credential verification succeeds."]]