Lorsqu'une application cliente inclut un jeton Web JSON (JWT) dans une requête adressée à une API, le proxy Extensible Service Proxy (ESP) valide le jeton avant d'envoyer la requête au backend de l'API. Cette page fournit des informations de dépannage en cas d'échec de validation JWT et si ESP affiche une erreur dans la réponse au client. Pour en savoir plus sur les jetons JWT, consultez la norme RFC 7519.
Erreur : 401: Jwt issuer is not configured
Cela peut se produire lors du déploiement d'ESPv2 dans Cloud Run. L'option --allow-unauthenticated n'est pas utilisée dans la commande gcloud run deploy.
Si l'option n'est pas utilisée, le jeton JWT est intercepté et vérifié par le serveur IAM de contrôle des accès Cloud Run <a=" docs="" managing-access"="" run="" securing="">et non par ESPv2. IAM peut utiliser un émetteur différent de ESPv2.
</a=">
Erreur : BAD_FORMAT
Vérifiez les éléments suivants :
Assurez-vous que le jeton JWT contient un JSON valide.
Vérifiez que le champ "alg" est présent dans l'en-tête du jeton JWT et que sa valeur est "RS256", "HS256", "RS384", "HS384", "RS512" ou "HS512".
Vérifiez le type de données des champs suivants, s'ils sont présents, dans la charge utile JWT :
Les déclarations "iat" (date/heure d'émission), "exp" (date/heure d'expiration) et "nbf" (pas avant le) sont des nombres supérieurs à 0 et non des chaînes.
Les champs "sub" (objet), "iss" (émetteur) et "jti" (ID JWT) sont des chaînes.
La déclaration "aud" (audience) est une chaîne ou un tableau de chaînes.
Assurez-vous que les déclarations suivantes sont présentes dans la charge utile du jeton JWT : "sub" (objet), "iss" (émetteur) et "aud" (audience).
Utilisez jwt.io pour décoder le jeton JWT et assurez-vous que :
la déclaration "exp" (date/heure d'expiration) est présente ;
la valeur de la déclaration "exp" (date/heure d'expiration) correspond à une date et une heure dans le futur ; la date et l'heure actuelles doivent être antérieures à la date et heure d'expiration indiquées dans la déclaration "exp" ;
la déclaration "nbf" (pas avant), si elle est présente, correspond à une date et une heure dans le passé . La date et l'heure actuelles doivent être postérieures ou identiques à la date et heure indiquées dans la déclaration "nbf".
Erreur : UNKNOWN
Utilisez jwt.io pour décoder le jeton JWT et vérifiez ce qui suit :
Si la déclaration "iss" (émetteur) est une adresse e-mail, les déclarations "sub" (objet) et "iss" doivent être identiques.
Cela permet de garantir que le jeton JWT est auto-émis pour les émetteurs via e-mail.
Error: KEY_RETRIEVAL_ERROR
Vérifiez que l'URI de clé publique spécifié dans le champ jwks_uri de la section authentication: providers de votre fichier de configuration gRPC .yaml est correct et valide.
Error: Issuer not allowed
Vérifiez que la déclaration "iss" (émetteur) de votre jeton JWT correspond au champ issuer de la section authentication: providers de votre fichier de configuration gRPC .yaml.
Error: Audience not allowed
Si la déclaration "aud" (audience) dans un jeton JWT correspond au nom du service Endpoints, l'ESP valide l'audience et ignore les valeurs audiences de votre fichier de configuration gRPC .yaml. Par exemple, si votre nom de service est "myservice.endpoints.example-project-12345.cloud.goog", un jeton JWT avec "aud" défini sur "myservice.endpoints.example-project-12345.cloud.goog" ou "https://myservice.endpoints.example-project-12345.cloud.goog" est une audience valide.
Si la déclaration "aud" n'est pas identique au nom du service Endpoints :
Vérifiez que la déclaration "aud" du jeton JWT correspond à l'une des valeurs audiences spécifiées dans la section authentication: providers de votre fichier de configuration gRPC .yaml.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/04 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/04 (UTC)."],[[["\u003cp\u003eThe Extensible Service Proxy (ESP) validates JSON Web Tokens (JWTs) before forwarding requests to the API backend, and this page offers troubleshooting for JWT validation failures.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eBAD_FORMAT\u003c/code\u003e error indicates potential issues with the JWT's structure, such as invalid JSON, incorrect \u003ccode\u003e"alg"\u003c/code\u003e field values, or incorrect data types for fields like \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.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eTIME_CONSTRAINT_FAILURE\u003c/code\u003e error means that either the \u003ccode\u003e"exp"\u003c/code\u003e (expiration time) claim is missing or invalid, or the \u003ccode\u003e"nbf"\u003c/code\u003e (not before) claim, if present, indicates that the token is not yet valid.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eKEY_RETRIEVAL_ERROR\u003c/code\u003e error suggests a problem with the \u003ccode\u003ejwks_uri\u003c/code\u003e specified in the gRPC configuration, which should be checked for accuracy.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eAudience not allowed\u003c/code\u003e error occurs when the \u003ccode\u003e"aud"\u003c/code\u003e claim in the JWT does not match either the Endpoints service name or the \u003ccode\u003eaudiences\u003c/code\u003e values specified in the gRPC configuration.\u003c/p\u003e\n"]]],[],null,["# Troubleshooting JWT validation\n\n[OpenAPI](/endpoints/docs/openapi/troubleshoot-jwt \"View this page for the Cloud Endpoints OpenAPI docs\") \\| gRPC\n\n\u003cbr /\u003e\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 [`jwks_uri`](/endpoints/docs/grpc/service-account-authentication#set_up_authentication_in_the_grpc_api_configuration) field in the `authentication: providers` section of your gRPC `.yaml` configuration file 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/grpc/service-account-authentication#set_up_authentication_in_the_grpc_api_configuration) field in the `authentication: providers` section of your gRPC `.yaml` configuration file.\n\n**Error: `Audience not allowed`**\n\nIf the `\"aud\"` (audience) claim in a JWT token matches the Endpoints\nservice name, then the ESP validates the audience\nand ignores the `audiences` values in your gRPC `.yaml` configuration file. For\nexample, if your service name is\n`\"myservice.endpoints.example-project-12345.cloud.goog\"`,\nthen a JWT with `\"aud\"` set to\n`\"myservice.endpoints.example-project-12345.cloud.goog\"`\nor `\"https://myservice.endpoints.example-project-12345.cloud.goog\"` 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 `audiences` values specified in the `authentication: providers` section of your gRPC `.yaml` configuration file."]]