Si votre requête API renvoie un message d'erreur indiquant que les identifiants de l'utilisateur ne sont pas compatibles avec cette API, que l'API n'est pas activée dans le projet ou qu'aucun projet de quota n'est défini, consultez les informations suivantes.
Il existe deux types d'API Google Cloud :
Les API basées sur des ressources, qui utilisent le projet associé aux ressources accessibles pour la facturation et les quotas.
Les API basées sur un client, qui utilisent le projet associé au client qui accède aux ressources pour la facturation et les quotas.
Lorsque vous fournissez des identifiants utilisateur pour vous authentifier auprès d'une API basée sur un client, vous devez spécifier le projet à utiliser pour la facturation et les quotas. Ce projet est appelé projet de quota.
Il existe plusieurs façons de spécifier un projet de quota, y compris les options suivantes :
Mettez à jour votre fichier ADC pour utiliser un projet différent comme projet de quota :
Si vous utilisez gcloud CLI pour appeler l'API, vous pouvez définir votre projet de quota dans votre configuration gcloud CLI :
gcloud config set billing/quota_project YOUR_PROJECT
Si vous appelez directement l'API REST ou RPC, utilisez l'en-tête HTTP x-goog-user-project pour spécifier un projet de quota dans chaque requête. Pour en savoir plus, consultez la section Définir le projet de quota avec une requête REST.
Vous devez disposer de l'autorisation IAM serviceusage.services.use pour un projet si vous souhaitez le désigner comme votre projet de facturation. L'autorisation serviceusage.services.use est incluse dans le rôle IAM Consommateur Service Usage. Si vous ne disposez pas de l'autorisation serviceusage.services.use pour un projet, contactez votre administrateur de sécurité ou un propriétaire de projet qui peut vous attribuer le rôle Consommateur Service Usage sur le projet.
Si vos identifiants ne semblent pas vous fournir l'accès attendu, ou si vous ne les trouvez pas, vérifiez les points suivants:
Si vous utilisez gcloud CLI pour accéder à Google Cloud dans un environnement local, assurez-vous de bien comprendre les identifiants que vous utilisez.
Lorsque vous utilisez gcloud CLI, vous utilisez les identifiants que vous avez fournis à gcloud CLI à l'aide de la commande gcloud auth login. Vous n'utilisez pas les identifiants que vous avez fournis au service ADC. Pour en savoir plus sur ces deux ensembles d'identifiants, consultez la page Configuration de l'authentification via gcloud CLI et configuration de l'ADC.
Assurez-vous que la variable d'environnement GOOGLE_APPLICATION_CREDENTIALS n'est définie que si vous utilisez une clé de compte de service ou un autre fichier JSON pour ADC.
Les identifiants pointés par la variable d'environnement sont prioritaires sur les autres identifiants, y compris pour Workload Identity Federation for GKE.
Vérifiez que le compte principal effectuant la requête dispose des rôles IAM requis. Si vous utilisez des identifiants utilisateur, les rôles doivent être attribués à l'adresse e-mail associée au compte utilisateur. Si vous utilisez un compte de service, ce compte doit disposer des rôles requis.
Si vous fournissez une clé API avec la requête API, la clé API est prioritaire sur ADC, quel qu'en soit l'emplacement. Si vous avez défini la variable d'environnement GOOGLE_APPLICATION_CREDENTIALS et que vous utilisez une clé API, celle-ci peut renvoyer un avertissement vous informant que les identifiants que vous avez fournis à ADC sont ignorés. Pour arrêter l'avertissement, supprimez la variable d'environnement GOOGLE_APPLICATION_CREDENTIALS.
Type d'identifiants non reconnus
Si votre requête API renvoie une erreur qui inclut "Erreur de création des identifiants à partir du fichier JSON. Type d'identifiant non reconnu", assurez-vous d'utiliser un identifiant valide. Les fichiers d'ID client ne sont pas compatibles avec la saisie des identifiants pour ADC.
Accès bloqué lors de l'utilisation de niveaux d'accès
Lorsque vous essayez de créer un fichier ADC local et qu'une erreur semblable à "Cette application est bloquée" ou "Accès bloqué : erreur d'autorisation" s'affiche, vous essayez peut-être d'utiliser des niveaux d'accès qui ne sont pas compatibles avec la commande de configuration ADC par défaut. En règle générale, ce problème est dû à l'ajout de niveaux d'accès pour des applications en dehors de Google Cloud, comme Google Drive.
Pour ajouter des niveaux d'accès pour des services en dehors de Google Cloud, tels que Google Drive, créez un ID client OAuth et fournissez-le à la commande gcloud auth application-default login en utilisant l'option –-client-id-file, en spécifiant vos niveaux d'accès avec l'option -–scopes.
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 2024/12/24 (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 2024/12/24 (UTC)."],[[["\u003cp\u003eThis page covers common issues encountered when using Application Default Credentials (ADC), including problems with user credentials, incorrect credentials, unrecognized credential types, errors with service account impersonation, quota project issues, and access blocked by scopes.\u003c/p\u003e\n"],["\u003cp\u003eWhen using client-based APIs with user credentials, a quota project must be specified for billing and quota purposes; this can be set through the ADC file, the gcloud CLI config, or the \u003ccode\u003ex-goog-user-project\u003c/code\u003e HTTP header.\u003c/p\u003e\n"],["\u003cp\u003eIf user credentials are not working, ensure that the API is enabled in the specified project, and that the user has the \u003ccode\u003eserviceusage.services.use\u003c/code\u003e IAM permission or the Service Usage Consumer role.\u003c/p\u003e\n"],["\u003cp\u003eWhen troubleshooting credential access problems, confirm that the correct credentials are being used, the \u003ccode\u003eGOOGLE_APPLICATION_CREDENTIALS\u003c/code\u003e environment variable is set appropriately, the requesting principal has the required IAM roles, and that an API key isn't overriding ADC.\u003c/p\u003e\n"],["\u003cp\u003eIf you receive an "Access blocked" error when creating a local ADC file, check if you're using scopes unsupported by the default ADC setup, and if necessary, use an OAuth Client ID to add scopes for non-Google Cloud services.\u003c/p\u003e\n"]]],[],null,["This page describes some common problems you might encounter when using\nApplication Default Credentials (ADC).\n\nFor information about how ADC works, including where credentials are found, see\n[How Application Default Credentials works](/docs/authentication/application-default-credentials).\n\nUser credentials not working\n\nIf your API request returns an error message about user credentials not being\nsupported by this API, the API not being enabled in the project, or no quota\nproject being set, review the following information.\n\nThere are two kinds of Google Cloud APIs:\n\n- *Resource-based APIs*, which use the project associated with the resources\n being accessed for billing and quota.\n\n- *Client-based APIs*, which use the project associated with the client\n accessing the resources for billing and quota.\n\nWhen you provide user credentials to authenticate to a client-based API, you\nmust specify the project to use for billing and quota. This project is called\nthe *quota project*.\n\nThere are a number of ways to specify a quota project, including the following\noptions:\n\n- Update your ADC file to use a different project as the quota project:\n\n ```\n gcloud auth application-default set-quota-project YOUR_PROJECT\n ```\n- If you are using the gcloud CLI to call the API, you can set\n your quota project in your gcloud CLI config:\n\n ```\n gcloud config set billing/quota_project YOUR_PROJECT\n ```\n- If you are calling the REST or RPC API directly, use the\n `x-goog-user-project` HTTP header to specify a quota project in each\n request. For details, see\n [Set the quota project with a REST request](/docs/authentication/rest#set-billing-project).\n\n| **Note:** The API you are trying to use must be enabled in whatever project you specify.\n\n\nYou must have the `serviceusage.services.use` IAM permission for\na project to be able to designate it as your billing project. The\n`serviceusage.services.use` permission is included in the Service Usage Consumer\nIAM role. If you don't have the `serviceusage.services.use`\npermission for any project, contact your security administrator or a project\nowner who can give you the Service Usage Consumer role in the project.\n\nFor more information about quota projects, see\n[Quota project overview](/docs/quotas/quota-project). For information about additional ways\nto set the quota project, see [Set the quota project](/docs/quotas/set-quota-project).\n\nIncorrect credentials\n\nIf your credentials don't seem to be providing the access you expect, or aren't\nfound, check the following:\n\n- If you are using the gcloud CLI to access Google Cloud in a\n local environment, make sure you understand which credentials you are using.\n When you use the gcloud CLI, you are using the credentials you\n provided to the gcloud CLI by using the `gcloud auth login`\n command. You are not using the credentials you provided to ADC. For more\n information about these two sets of credentials, see\n [gcloud CLI authentication configuration and ADC configuration](/docs/authentication/gcloud#gcloud-credentials).\n\n- Make sure that the `GOOGLE_APPLICATION_CREDENTIALS` environment variable is\n set *only* if you are using a service account key or other JSON file for ADC.\n The credentials pointed to by the environment variable take precedence over\n other credentials, including for Workload Identity Federation for GKE.\n\n- Confirm that the principal making the request has the required\n IAM roles. If you are using user credentials, then the roles\n must be granted to the email address associated with the user account. If\n you are using a service account, then that service account must have the\n required roles.\n\n- If you provide an API key with the API request, the API key takes precedence\n over ADC in any location. If you have set the `GOOGLE_APPLICATION_CREDENTIALS`\n environment variable and you are using an API key, the API might return a\n warning telling you that the credentials you provided to ADC are being\n ignored. To stop the warning, unset the `GOOGLE_APPLICATION_CREDENTIALS`\n environment variable.\n\nUnrecognized credential type\n\nIf your API request returns an error that includes `Error creating credential\nfrom JSON. Unrecognized credential type`, make sure you are using a valid\ncredential. Client ID files are not supported to provide credentials for ADC.\n\nError returned for local credentials from service account impersonation\n\nCredentials from a local ADC file generated by using service account\nimpersonation are not supported by all of the authentication libraries. If your\ncall returns an error similar to `Neither metadata server or valid service\naccount credentials are found`, you can't use local impersonated credentials for\nthis task.\n\nTo avoid this error, create your ADC file from your user credentials or run your\ncode in an environment that has a metadata server available (such as\nCompute Engine).\n\nUnknown project `764086051850` used for request\n\nProject `764086051850` is the project used by the gcloud CLI. If you\nsee authentication errors referencing this project, you are trying to use\na client-based API and you have not set both your project and your quota\nproject for your configuration.\n\nFor more information, see [User credentials not working](#user-creds-client-based).\n\nAccess blocked when using scopes\n\nWhen you attempt to create a local ADC file, and an error similar to `This app\nis blocked` or `Access blocked: Authorization Error` is returned, you might be\nattempting to use scopes that aren't supported by the\n[default ADC setup command](/docs/authentication/set-up-adc-local-dev-environment#google-idp). Typically, this issue is caused by\nadding scopes for applications outside of Google Cloud, such as Google\nDrive.\n\n\nBy default, the access tokens generated from a local ADC file created with user credentials include\nthe [cloud-wide scope `https://www.googleapis.com/auth/cloud-platform`](/docs/authentication#authorization-gcp).\nTo specify scopes explicitly, you use the\n[`---scopes` flag](/sdk/gcloud/reference/auth/application-default/login#--scopes)\nwith the `gcloud auth application-default login` command.\n\n\nTo add scopes for services outside of Google Cloud, such as Google Drive,\n[create an OAuth Client ID](https://support.google.com/cloud/answer/6158849)\nand provide it to the `gcloud auth application-default login` command by using the\n[`---client-id-file` flag](/sdk/gcloud/reference/auth/application-default/login#--client-id-file), specifying\nyour scopes with the [`---scopes` flag](/sdk/gcloud/reference/auth/application-default/login#--scopes)."]]