Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Quando um aplicativo cliente inclui um Token da Web JSON (JWT, na sigla em inglês) em uma solicitação para uma API, o Extensible Service Proxy (ESP) valida o JWT antes de enviar a solicitação ao back-end da API. Nesta página, você verá informações sobre solução de problemas se a validação do JWT falhar e o ESP retornar um erro na resposta ao cliente. Consulte RFC 7519 para saber mais sobre JWTs.
Erro: 401: Jwt issuer is not configured
Isso pode acontecer se, ao implantar o ESPv2 no Cloud Run, a sinalização
--allow-unauthenticated não for usada no comando gcloud run deploy.
Se a sinalização não for usada, o token JWT será interceptado
e verificado pelo servidor IAM de <a=" docs="" managing-access"="" run="" securing="">controle
de acesso do Cloud Run e não do ESPv2. O IAM pode usar um emissor diferente de
ESPv2.
</a=">
Erro: BAD_FORMAT
Verifique o seguinte:
Verifique se o JWT contém um JSON válido.
Se o cabeçalho JWT tem o campo "alg" e é definido como um dos seguintes: "RS256", "HS256", "RS384", "HS384", "RS512" ou "HS512".
Verifique o tipo de dados dos seguintes campos, se eles estiverem presentes, no payload do JWT:
Se as declarações "iat" (emitido às), "exp" (prazo de validade) e "nbf" (não antes) são números maiores que 0 e não strings.
Se os campos "sub" (assunto), "iss" (emissor) e "jti" (ID do JWT) são strings.
Se a declaração "aud" (público-alvo) é uma string ou uma matriz de strings.
Certifique-se de que as seguintes declarações estejam presentes no payload do JWT: "sub" (assunto), "iss" (emissor) e "aud" (público-alvo).
A seguir, você encontra um exemplo de token decodificado do JWT válido:
Use jwt.io (em inglês) para decodificar o JWT e verifique o seguinte:
A declaração "exp" (prazo de validade) existe.
O valor da declaração "exp" (prazo de validade) é uma data e hora no futuro. A data e a hora atuais devem ser anteriores ao prazo de validade e ao horário listados na declaração "exp".
A declaração "nbf" (não antes de), se presente, é uma data e um horário no passado. A data e hora atuais devem ser posteriores ou iguais à data e hora listadas na declaração "nbf".
Erro: UNKNOWN
Use jwt.io (em inglês) para decodificar o JWT e verifique o seguinte:
Se a declaração "iss" (emissor) for um endereço de e-mail, as declarações "sub" (assunto) e "iss" devem ser as mesmas.
Isso garante que o JWT seja autoemitido para emissores por e-mail.
Erro: KEY_RETRIEVAL_ERROR
Verifique se o URI de chave pública especificado no
jwksUri
na anotação ApiIssuer está correto e é válido.
Erro: Issuer not allowed
Verifique se a declaração "iss" (emissor) no seu token do JWT corresponde ao
valor de issuer
na anotação ApiIssuer.
Erro: Audience not allowed
Se a declaração "aud" (público-alvo) em um token do JWT corresponde ao
nome do serviço do Endpoints, o Cloud Endpoints Frameworks valida
o público-alvo e ignora os valores definidos no
elemento audiences
na anotação ApiIssuerAudience. Por exemplo, se o nome do serviço for "myservice.appspot.com", um JWT com "aud" definido como "myservice.appspot.com" ou "https://myservice.appspot.com" será um público-alvo válido.
Se a declaração "aud" não for igual ao nome do serviço do
Endpoints:
Verifique se a declaração "aud" no JWT corresponde a um dos valores no
elemento audiences na anotação ApiIssuerAudience.
[[["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\u003eThe Extensible Service Proxy (ESP) validates JSON Web Tokens (JWTs) before requests reach the API backend, and this document provides guidance for troubleshooting JWT validation failures.\u003c/p\u003e\n"],["\u003cp\u003eJWT validation errors such as \u003ccode\u003e401: Jwt issuer is not configured\u003c/code\u003e, \u003ccode\u003eBAD_FORMAT\u003c/code\u003e, \u003ccode\u003eTIME_CONSTRAINT_FAILURE\u003c/code\u003e, \u003ccode\u003eUNKNOWN\u003c/code\u003e, \u003ccode\u003eKEY_RETRIEVAL_ERROR\u003c/code\u003e, \u003ccode\u003eIssuer not allowed\u003c/code\u003e, and \u003ccode\u003eAudience not allowed\u003c/code\u003e can occur due to various configuration and format issues.\u003c/p\u003e\n"],["\u003cp\u003eEnsure that JWTs are correctly formatted with valid JSON, and have required fields such as \u003ccode\u003e"alg"\u003c/code\u003e, \u003ccode\u003e"iat"\u003c/code\u003e, \u003ccode\u003e"exp"\u003c/code\u003e, \u003ccode\u003e"nbf"\u003c/code\u003e, \u003ccode\u003e"sub"\u003c/code\u003e, \u003ccode\u003e"iss"\u003c/code\u003e, \u003ccode\u003e"jti"\u003c/code\u003e, and \u003ccode\u003e"aud"\u003c/code\u003e with the correct data types and values.\u003c/p\u003e\n"],["\u003cp\u003eVerify that time-related claims like \u003ccode\u003e"exp"\u003c/code\u003e and \u003ccode\u003e"nbf"\u003c/code\u003e are appropriately set for the current time, and use tools like jwt.io to decode and inspect the JWT's contents.\u003c/p\u003e\n"],["\u003cp\u003eProper configuration of the public key URI (\u003ccode\u003ejwksUri\u003c/code\u003e) and issuer (\u003ccode\u003eiss\u003c/code\u003e) are crucial to avoid errors such as \u003ccode\u003eKEY_RETRIEVAL_ERROR\u003c/code\u003e and \u003ccode\u003eIssuer not allowed\u003c/code\u003e, and the \u003ccode\u003eaud\u003c/code\u003e (audience) must match the service name or be within the allowed \u003ccode\u003eaudiences\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["# Troubleshooting JWT validation\n\nWhen a client application includes a JSON Web Token (JWT) in a request to an\nAPI, the [Extensible Service Proxy (ESP)](/endpoints/docs/openapi/glossary#extensible_service_proxy)\nvalidates the JWT before sending the request to the API\nbackend. This page provides troubleshooting information if the JWT validation\nfails and ESP returns an error in the response to the client. See\n[RFC 7519](https://tools.ietf.org/html/rfc7519) for more information\nabout JWTs.\n**Error: `401: Jwt issuer is not configured`**\n\nThis may happen when deploying ESPv2 in Cloud Run, the flag\n`--allow-unauthenticated` is not used in `gcloud run deploy` command.\nIf the flag is not used, the JWT token is intercepted\nand verified by Cloud Run access control IAM server and not by ESPv2. IAM may use a different issuer than ESPv2.\n**Error: `BAD_FORMAT`**\n\nCheck the\nfollowing:\n\n- Make sure the JWT contains valid JSON.\n- Check that the JWT header has the `\"alg\"` field and is set to one of the following: `\"RS256\"`, `\"HS256\"`, `\"RS384\"`, `\"HS384\"`, `\"RS512\"`, or `\"HS512\"`\n- Check the data type of the following fields (if they are present) in the JWT payload:\n - The `\"iat\"` (issued at), `\"exp\"` (expiration time), and `\"nbf\"`(not before) claims are numbers greater than 0 and not strings.\n - The `\"sub\"` (subject), `\"iss\"` (issuer), and `\"jti\"` (JWT ID) fields are strings.\n - The `\"aud\"` (audience) claim is either a string or an array of strings.\n- Ensure that the following claims are present in the JWT payload: `\"sub\"` (subject), `\"iss\"` (issuer), and `\"aud\"` (audience).\n\nThe following is an example of a decoded JWT token that is valid: \n\n```\n{\n \"alg\": \"RS256\",\n \"typ\": \"JWT\",\n \"kid\": \"42ba1e234ac91ffca687a5b5b3d0ca2d7ce0fc0a\"\n}\n\nPayload:\n{\n \"iss\": \"myservice@myproject.iam.gserviceaccount.com\",\n \"iat\": 1493833746,\n \"aud\": \"myservice.appspot.com\",\n \"exp\": 1493837346,\n \"sub\": \"myservice@myproject.iam.gserviceaccount.com\"\n}\n```\n**Error: `TIME_CONSTRAINT_FAILURE`**\n\nUse [jwt.io](https://jwt.io/) to decode the JWT and make sure that:\n\n- The `\"exp\"` (expiration time) claim exists.\n- The `\"exp\"` (expiration time) claim value is a date and time in the future. The current date and time must be before the expiration date and time listed in the `\"exp\"` claim.\n- The `\"nbf\"` (not before) claim (If present) is a date and time in the past. The current date and time must be after or equal to the date and time listed in the `\"nbf\"` claim.\n\n**Error: `UNKNOWN`**\n\nUse [jwt.io](https://jwt.io/) to decode the JWT and ensure that:\n\n- If the `\"iss\"` (issuer) claim is an email address, then the `\"sub\"` (subject) and `\"iss\"` claims should be the same. This is to ensure that for e-mail issuers, the JWT is self issued.\n\n**Error: `KEY_RETRIEVAL_ERROR`**\n\n- Check that the public key URI specified in the [`jwksUri`](/endpoints/docs/frameworks/java/javadoc/com/google/api/server/spi/config/ApiIssuer) in the `ApiIssuer` annotation is correct and valid.\n\n**Error: `Issuer not allowed`**\n\n- Check that the `\"iss\"` (issuer) claim in your JWT token matches the [`issuer`](/endpoints/docs/frameworks/java/javadoc/com/google/api/server/spi/config/ApiIssuer) value in the `ApiIssuer` annotation.\n\n**Error: `Audience not allowed`**\n\nIf the `\"aud\"` (audience) claim in a JWT token matches the\nEndpoints service name, then Cloud Endpoints Frameworks validates\nthe audience and ignores the values set in the\n[`audiences`](/endpoints/docs/frameworks/java/javadoc/com/google/api/server/spi/config/ApiIssuerAudience)\nelement in the `ApiIssuerAudience` annotation. For example, if your service name\nis `\"myservice.appspot.com\"`, then a JWT with `\"aud\"` set to\n`\"myservice.appspot.com\"` or `\"https://myservice.appspot.com\"` is a valid\naudience.\n\nIf the `\"aud\"` claim isn't the same as the Endpoints service\nname:\n\n- Check that the `\"aud\"` claim in the JWT matches one of the values in the `audiences` element in the `ApiIssuerAudience` annotation."]]