Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
ID de la région
Le REGION_ID est un code abrégé que Google attribue en fonction de la région que vous sélectionnez lors de la création de votre application. Le code ne correspond pas à un pays ou une province, même si certains ID de région peuvent ressembler aux codes de pays et de province couramment utilisés. Pour les applications créées après février 2020, REGION_ID.r est inclus dans les URL App Engine. Pour les applications existantes créées avant cette date, l'ID de région est facultatif dans l'URL.
Pour utiliser l'authentification Firebase avec votre service Web, ajoutez Firebase à votre projet Google Cloud et configurez vos paramètres d'authentification.
Ajoutez Firebase à votre projet Google Cloud existant à l'aide de l'outil Ajouter un projet de la console Firebase.
Vous pouvez également choisir d'utiliser un compte Firebase sous un nom différent, non associé à votre projet Google Cloud existant.
Dans la console Firebase, activez les fournisseurs de connexion avec authentification. Pour ce service Web, vous activez les fournisseurs de connexion Email/Password (Adresse e-mail/Mot de passe) et Google :
Cliquez sur Build > Authentication > Sign-in method (Compiler > Authentification > Méthode de connexion).
Sous Fournisseurs de connexion, sélectionnez Adresse e-mail/Mot de passe.
Cochez la case Enable (Activer) pour utiliser l'authentification par adresse e-mail et mot de passe, puis cliquez sur Save (Enregistrer).
Pour que l'authentification Firebase fonctionne correctement, votre domaine doit être autorisé pour les redirections OAuth. Pour autoriser votre domaine :
Sous Authorized domains (Domaines autorisés) sur la page Settings (Paramètres), cliquez sur Add Domain (Ajouter un domaine).
Saisissez le domaine de votre application sur App Engine, en excluant le préfixe http:// :
PROJECT_ID.
REGION_ID.r.appspot.com
où PROJECT_ID est l'ID de votre projetGoogle Cloud .
Ajouter Firebase à votre service Web
Pour ajouter Firebase à votre service Web, copiez l'extrait de code personnalisé, les fichiers JavaScript et CSS de votre projet Firebase dans votre service Web :
Sur la page de présentation du projet, sous Lancez-vous en ajoutant Firebase à votre application, sélectionnez Web. Si vous avez déjà ajouté une application au projet, ce texte risque de ne pas s'afficher. Accédez à la page de présentation du projet > Paramètres du projet > Général de votre application existante, faites défiler la page vers le bas, puis sélectionnez Ajouter une application
Une fois l'application enregistrée, un extrait de code personnalisé s'affiche. Copiez le contenu de l'extrait. Pour afficher de nouveau cet extrait de code ultérieurement, accédez à la page Paramètres du projet de votre application Firebase.
Mettez à jour votre fichier templates/index.html en procédant comme suit :
Ajoutez votre extrait de code personnalisé dans la balise <body>.
Pour ce tutoriel, vous pouvez ajouter le code en haut du corps du fichier, car le seul contenu de templates/index.html est un exemple de services Firebase. Dans votre environnement de production, nous vous recommandons d'ajouter l'extrait de code en bas du corps du fichier, mais avant d'appeler les services Firebase.
Votre code personnalisé se présentera comme suit :
Remplacez le reste du corps du fichier par le code suivant, que vous utiliserez plus loin dans ce guide pour afficher les données des utilisateur authentifiés :
Maintenant que vous avez ajouté Firebase à votre projet Google Cloud et à votre service Web, vous êtes prêt à ajouter du code au service pour lui permettre d'authentifier les utilisateurs.
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 \u003ccode\u003eREGION_ID\u003c/code\u003e is a Google-assigned code based on the region selected during app creation, which is included in App Engine URLs for apps created after February 2020.\u003c/p\u003e\n"],["\u003cp\u003eFirebase can be added to a Google Cloud project to enable user authentication for a personalized web service experience.\u003c/p\u003e\n"],["\u003cp\u003eAdding Firebase to your Google Cloud project involves using the Firebase console to add your project, enabling authentication sign-on providers like Email/Password and Google, and authorizing your domain for OAuth redirects.\u003c/p\u003e\n"],["\u003cp\u003eAdding Firebase to a web service involves copying a customized code snippet, JavaScript, and CSS files from the Firebase console into the service's \u003ccode\u003eindex.html\u003c/code\u003e file, ensuring the Firebase Authentication component is properly included.\u003c/p\u003e\n"],["\u003cp\u003eTo continue, you have to add code to your web service that will enable user authentication.\u003c/p\u003e\n"]]],[],null,["# Add Firebase to your web service\n\n### Region ID\n\nThe \u003cvar translate=\"no\"\u003eREGION_ID\u003c/var\u003e is an abbreviated code that Google assigns\nbased on the region you select when you create your app. The code does not\ncorrespond to a country or province, even though some region IDs may appear\nsimilar to commonly used country and province codes. For apps created after\nFebruary 2020, \u003cvar translate=\"no\"\u003eREGION_ID\u003c/var\u003e`.r` is included in\nApp Engine URLs. For existing apps created before this date, the\nregion ID is optional in the URL.\n\nLearn more\n[about region IDs](/appengine/docs/standard/python3/how-requests-are-routed#region-id). \nOK\n\n\u003cbr /\u003e\n\n| **Note:** If you are deploying a new Python web service to Google Cloud, we recommend getting started with [Cloud Run](/run/docs/quickstarts/build-and-deploy/deploy-python-service).\n\nAdd Firebase to your Google Cloud project, configure your authentication\nsettings, and then add Firebase to your web service.\n\nAdding Firebase to your web service enables you to authenticate users\nso that you can give each user a personalized experience.\n\nBefore you begin\n----------------\n\nIf you have completed all the previous steps in this guide, skip this section.\nOtherwise, complete one of the following:\n\n- Start from [Build a Python 3 App](/appengine/docs/standard/python3/building-app)\n and complete all the steps leading up to this one.\n\n- If you already have a\n [Google Cloud project](/appengine/docs/standard/python3/building-app/creating-gcp-project),\n you can continue by downloading a copy of the web service:\n\n 1. Download the sample application repository using\n [Git](https://git-scm.com/):\n\n git clone https://github.com/GoogleCloudPlatform/python-docs-samples\n\n Alternatively, you can [download the sample](https://github.com/GoogleCloudPlatform/python-docs-samples/archive/master.zip) as a zip\n file and then extract it.\n 2. Navigate to the directory that contains a copy of the files from the\n previous step:\n\n cd python-docs-samples/appengine/standard_python3/building-an-app/building-an-app-1\n\nAdd Firebase to your Google Cloud project\n-----------------------------------------\n\nTo use Firebase authentication with your web service, add\nFirebase to your Google Cloud project and configure your authentication\nsettings.\n\n1. Add Firebase to your existing Google Cloud project using the\n **Add project** tool in the [Firebase console](https://console.firebase.google.com/).\n\n You can also choose to use a Firebase account with a different name, not\n associated with your existing Google Cloud project.\n2. Enable the authentication sign-on providers in the\n [Firebase console](https://console.firebase.google.com/). For this\n web service, you will enable **Email/Password** and **Google** sign-in\n providers:\n\n 1. Click **Build** \\\u003e **Authentication** \\\u003e **Sign-in method**.\n\n 2. Under **Sign-in providers** , select **Email/Password**.\n\n 3. Toggle the **Enable** button to use email and password authentication,\n and click **Save**.\n\n | **Tip:** For more information about enabling other providers, see the \"Before you begin\" sections of the [Google](https://firebase.google.com/docs/auth/web/google-signin), [Facebook](https://firebase.google.com/docs/auth/web/facebook-login), [Twitter](https://firebase.google.com/docs/auth/web/twitter-login), and [GitHub](https://firebase.google.com/docs/auth/web/github-auth) guides on Firebase.\n3. For Firebase to authenticate properly, your domain needs to be authorized\n for OAuth redirects. To authorize your domain:\n\n 1. Select **Build** \\\u003e **Authentication** \\\u003e **Settings**.\n\n 2. Under **Authorized domains** on the **Settings** page, click **Add Domain**.\n\n 3. Enter the domain of your app on App Engine, excluding the\n `http://` prefix:\n\n \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e.\n \u003cvar translate=\"no\"\u003e\u003ca href=\"#appengine-urls\" style=\"border-bottom: 1px dotted #999\" class=\"devsite-dialog-button\" data-modal-dialog-id=\"regional_url\" track-type=\"progressiveHelp\" track-name=\"modalHelp\" track-metadata-goal=\"regionalURL\"\u003eREGION_ID\u003c/a\u003e\u003c/var\u003e`.r.appspot.com`\n where \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e is the ID of your\n Google Cloud project.\n\nAdd Firebase to your web service\n--------------------------------\n\nTo add Firebase to your web service, copy your Firebase project's custom code\nsnippet, JavaScript and CSS files into your web service:\n\n1. Go to the [Firebase console](https://console.firebase.google.com/) and select your project.\n\n2. From the project overview page, under the text **Get started by adding\n Firebase to your app** , select **web** . If you already have an app added to\n the project, you may not see this text; instead, navigate to the\n **Project Overview** \\\u003e **Project settings** \\\u003e **General**\n page of your existing app, scroll down, and select **Add app**.\n\n3. Once the app is registered, a customized code snippet will be displayed. Copy\n the contents of the snippet. To see this code snippet again later, navigate\n to the **Project settings** page for your Firebase app.\n\n4. Update your `templates/index.html` file by completing the following:\n\n 1. Add the following lines to the `\u003chead\u003e` tag:\n\n \u003cscript src=\"https://www.gstatic.com/firebasejs/ui/6.0.1/firebase-ui-auth.js\"\u003e\u003c/script\u003e\n \u003clink type=\"text/css\" rel=\"stylesheet\" href=\"https://www.gstatic.com/firebasejs/ui/6.0.1/firebase-ui-auth.css\" /\u003e\n\n 2. Add your customized code snippet to the `\u003cbody\u003e` tag.\n\n For this tutorial, you can add the code to the top of the body, since the\n only content in `templates/index.html` is an example of Firebase\n services. In your production environment, we recommend that you add the\n code snippet to the bottom of the body, but before you use any Firebase\n services.\n\n Your custom code will look similar to this mock snippet: \n\n \u003c!-- MOCK SNIPPET: DO NOT COPY --\u003e\n \u003c!-- The core Firebase JS SDK is always required and must be listed first --\u003e\n \u003cscript src=\"https://www.gstatic.com/firebasejs/7.14.5/firebase-app.js\"\u003e\u003c/script\u003e\n\n \u003c!-- TODO: Add SDKs for Firebase products that you want to use\n https://firebase.google.com/docs/web/setup#available-libraries --\u003e\n\n \u003cscript\u003e\n var config = {\n apiKey: \"\u003cAPI_KEY\u003e\",\n authDomain: \"\u003cPROJECT_ID\u003e.firebaseapp.com\",\n databaseURL: \"https://\u003cDATABASE_NAME\u003e.firebaseio.com\",\n projectId: \"\u003cPROJECT_ID\u003e\",\n storageBucket: \"\u003cBUCKET\u003e.appspot.com\",\n messagingSenderId: \"\u003cSENDER_ID\u003e\",\n };\n firebase.initializeApp(config);\n \u003c/script\u003e\n\n 3. Replace the TODO in the snippet above with the following script tag to\n enable the Authentication component of Firebase:\n\n \u003cbr /\u003e\n\n ```\n \u003cscript src=\"https://www.gstatic.com/firebasejs/7.8.0/firebase-auth.js\"\u003e\u003c/script\u003e\n \n ```\n\n \u003cbr /\u003e\n\n These script addresses are documented in the [Firebase UI for Web\n documentation](https://firebaseopensource.com/projects/firebase/firebaseui-web/).\n 4. Replace the rest of the body with the following code, which you will use\n later in this guide to display authenticated user data:\n\n \u003cdiv id=\"firebaseui-auth-container\"\u003e\u003c/div\u003e\n\n \u003cbutton id=\"sign-out\" hidden=true\u003eSign Out\u003c/button\u003e\n\n \u003cdiv id=\"login-info\" hidden=true\u003e\n \u003ch2\u003eLogin info:\u003c/h2\u003e\n {% if user_data %}\n \u003cdl\u003e\n \u003cdt\u003eName\u003c/dt\u003e\u003cdd\u003e{{ user_data['name'] }}\u003c/dd\u003e\n \u003cdt\u003eEmail\u003c/dt\u003e\u003cdd\u003e{{ user_data['email'] }}\u003c/dd\u003e\n \u003cdt\u003eLast 10 visits\u003c/dt\u003e\u003cdd\u003e\n \t{% for time in times %}\n \u003cp\u003e{{ time['timestamp'] }}\u003c/p\u003e\n {% endfor %} \u003c/dd\u003e\n \u003c/dl\u003e\n {% elif error_message %}\n \u003cp\u003eError: {{ error_message }}\u003c/p\u003e\n {% endif %}\n \u003c/div\u003e\n\nNext Steps\n----------\n\nNow that you've added Firebase to your Google Cloud project and your web\nservice, you're ready to add code to your web service to enable it to\nauthenticate users."]]