Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Si vous souhaitez exiger une authentification pour accéder au backend de l'API, vous devez obtenir les ID clients requis et les fournir au backend à l'aide de l'attribut d'annotation d'API approprié.
Android
Pour créer l'ID client OAuth 2.0 Android, vous devez disposer d'une empreinte de clé de certificat. Si vous utilisez Android Studio, un magasin de clés de débogage et une clé de débogage sont créés automatiquement. Vous pouvez utiliser cette dernière à des fins de test, mais vous devez utiliser une clé de libération pour la production.
Notez que le mot de passe du magasin de clés de débogage par défaut est android, et que l'alias de la clé est androiddebugkey. L'emplacement par défaut pour Linux et macOS est ~/.android/debug.keystore.
Si vous ne possédez pas encore de clé de débogage ou de libération, générez-en une pour l'application Android. Si vous utilisez Android Studio, ce dernier génère automatiquement une clé de débogage dans le magasin de clés de débogage la première fois que vous créez un projet Android.
Dans une fenêtre de terminal Linux ou macOS, vous pouvez obtenir l'empreinte de la clé à l'aide de la commande keytool (incluse dans le SDK Java) comme suit :
Vous devriez obtenir une empreinte semblable à celle-ci :
DA:39:A3:EE:5E:6B:4B:0D:32:55:BF:EF:95:60:18:90:AF:D8:07:09
Copiez et enregistrez l'empreinte de la clé qui s'affiche une fois que vous avez exécuté la commande keytool précédente. Vous devez fournir l'empreinte pour générer l'ID client Android dans la console Google Cloud .
Dans la Google Cloud console, accédez à la page Identifiants.
Dans la liste des projets, sélectionnez le projet contenant l'API.
Si c'est la première fois que vous créez un ID client dans ce projet, suivez les sous-étapes pour accéder à la page Autorisation OAuth. Sinon, passez à l'étape suivante.
Cliquez sur l'écran d'autorisation OAuth.
Saisissez un nom dans le champ Nom de l'application.
Remplissez le reste des champs selon les besoins.
Cliquez sur Save.
Dans le menu déroulant Créer des identifiants, sélectionnez ID client OAuth.
Sélectionnez Android comme type d'application.
Dans Nom, saisissez un nom pour votre ID client.
Dans Empreinte du certificat de signature, saisissez l'empreinte que vous avez obtenue ci-dessus.
Dans Nom du package, saisissez le nom du package de l'application Android, tel que spécifié dans le fichier AndroidManifest.xml.
Cliquez sur Créer.
Vous pouvez utiliser l'ID client généré dans le backend de votre API et dans votre application cliente.
Client Web
Dans la Google Cloud console, accédez à la page Identifiants.
Dans la liste des projets, sélectionnez le projet contenant l'API.
Si c'est la première fois que vous créez un ID client dans ce projet, suivez les sous-étapes pour accéder à la page Autorisation OAuth. Sinon, passez à l'étape suivante.
Cliquez sur l'écran d'autorisation OAuth.
Saisissez un nom dans le champ Nom de l'application.
Remplissez le reste des champs selon les besoins.
Cliquez sur Save.
Dans le menu déroulant Créer des identifiants, sélectionnez ID client OAuth.
Sélectionnez Application Web comme type d'application.
Dans Nom, saisissez un nom pour votre ID client.
Dans Origines JavaScript autorisées, saisissez l'un des éléments suivants :
https://YOUR_PROJECT_ID.appspot.com, en remplaçant YOUR_PROJECT_ID par votre ID de projet App Engine, si vous déployez votre API backend sur votre App Engine de production.
Cliquez sur Créer.
Vous pouvez utiliser l'ID client généré dans le backend de votre API et dans votre application cliente.
Étapes suivantes
Pour en savoir plus sur la façon d'assurer l'authentification dans l'application Android ou JavaScript, consultez les pages suivantes :
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\u003eAuthentication for API access requires obtaining and supplying client IDs via API annotation attributes.\u003c/p\u003e\n"],["\u003cp\u003eAndroid client ID creation necessitates a certificate key fingerprint, obtainable using the \u003ccode\u003ekeytool\u003c/code\u003e command with either a debug or release keystore.\u003c/p\u003e\n"],["\u003cp\u003eThe Google Cloud console's Credentials page is where you manage the creation of both Android and web OAuth 2.0 client IDs.\u003c/p\u003e\n"],["\u003cp\u003eFor web clients, ensure that the "Authorized JavaScript origins" in the web client settings use the correct protocol, either \u003ccode\u003ehttp\u003c/code\u003e for local testing or \u003ccode\u003ehttps\u003c/code\u003e for deployed applications.\u003c/p\u003e\n"],["\u003cp\u003eGenerated client IDs are used in both the API backend and the corresponding client application.\u003c/p\u003e\n"]]],[],null,["# Creating client IDs\n\nIf you want to require authentication to access your API backend, you must obtain\nthe required client IDs and supply them to the backend by using the proper API\nannotation attribute.\n\n\n### Android\n\n\nTo create the OAuth 2.0 Android client ID, you need to have a\ncertificate key fingerprint. If you use Android Studio, a debug keystore\nand a debug key are created automatically. You can use the debug key for\ntesting purposes, but you must use a release key for production.\n\n\nNote that the default debug keystore password is `android`, and\nthe key alias is `androiddebugkey`. The default location for Linux\nand macOS is `~/.android/debug.keystore`.\n| **Warning:** When you create a release key, don't use `android` as your release key or keystore password.\n\n1. If you don't already have one, generate a debug or release key for your Android application. If you use Android Studio, it automatically generates a debug key in the debug keystore the first time you build an Android project.\n2. In a Linux or macOS terminal window, you can get the fingerprint of the key by using the `keytool` included with the Java SDK as follows: \n\n ```java\n keytool -exportcert -alias androiddebugkey -keystore path-to-debug-or-production-keystore -list -v\n ```\n The output displays a fingerprint similar to the following: `DA:39:A3:EE:5E:6B:4B:0D:32:55:BF:EF:95:60:18:90:AF:D8:07:09`\n3. Copy and save the key fingerprint that is displayed after your run the preceding `keytool` command. You need to supply the fingerprint to generate the Android client ID in the Google Cloud console.\n4. In the Google Cloud console, go to the **Credentials** page.\n\n [Go to the Credentials page](https://console.cloud.google.com/apis/credentials)\n5. From the projects list, select the project containing your API.\n6. If this is your first time creating a client ID in this project, use the sub-steps to go to the **OAuth consent** page; otherwise, skip to the next step.\n 1. Click **OAuth consent screen**.\n 2. Enter a name in the **Application name** field.\n 3. Fill out the rest of the fields as needed.\n 4. Click **Save**.\n7. In the **Create credentials** drop-down list, select **OAuth client ID**.\n8. Select **Android** as the application type.\n9. In **Name**, enter a name for your client ID.\n10. In **Signing-certificate fingerprint**, enter the fingerprint you obtained previously.\n11. In **Package name** , enter the Android application package name, as specified in your `AndroidManifest.xml` file.\n12. Click **Create** .\n\n\n You use the generated client ID in your API backend and in your client\n application.\n\n### Web client\n\n1. In the Google Cloud console, go to the **Credentials** page.\n\n [Go to the Credentials page](https://console.cloud.google.com/apis/credentials)\n2. From the projects list, select the project containing your API.\n3. If this is your first time creating a client ID in this project, use the sub-steps to go to the **OAuth consent** page; otherwise, skip to the next step.\n 1. Click **OAuth consent screen**.\n 2. Enter a name in the **Application name** field.\n 3. Fill out the rest of the fields as needed.\n 4. Click **Save**.\n4. In the **Create credentials** drop-down list, select **OAuth client ID**.\n5. Select **Web application** as the application type.\n6. In **Name**, enter a name for your client ID.\n7. In **Authorized JavaScript origins** , enter one of the following:\n - `http://localhost:8080` if you are [testing the backend locally](/endpoints/docs/frameworks/java/test-deploy#running_and_testing_api_backends_locally).\n -\n `https://`\u003cvar translate=\"no\"\u003eYOUR_PROJECT_ID\u003c/var\u003e`.appspot.com`,\n replacing \u003cvar translate=\"no\"\u003eYOUR_PROJECT_ID\u003c/var\u003e\n with your App Engine project ID if you are deploying your\n backend API to your production App Engine.\n\n | **Important:** You must specify the site or host name under **Authorized JavaScript origins** using `https` for this to work with Cloud Endpoints, unless you are testing with `localhost`, in which case you must use `http`.\n8. Click **Create** .\n\n\n You use the generated client ID in your API backend and in your client\n application.\n\nWhat's next\n-----------\n\nFor information about how to support authentication in your Android or\nJavaScript application, see the following:\n\n- [Authenticating users](/endpoints/docs/frameworks/java/authenticating-users)\n- [Making authenticated calls from an Android client](/endpoints/docs/frameworks/java/calling-from-android#making_authenticated_calls)"]]