Add Firebase to your Google Cloud project, configure your authentication settings, and then add Firebase to your web service.
Adding Firebase to your web service enables you to authenticate users so that you can give each user a personalized experience.
Before you begin
If you have completed all the previous steps in this guide, skip this section. Otherwise, complete one of the following:
Start from Building a Python 3.7 App and complete all the steps leading up to this one.
If you already have a Google Cloud project, you can continue by downloading a copy of the web service:
Download the sample application repository using Git:
git clone https://github.com/GoogleCloudPlatform/python-docs-samples
Alternatively, you can download the sample as a zip file and then extract it.
Navigate to the directory that contains a copy of the files from the previous step:
cd python-docs-samples/appengine/standard_python37/building-an-app/building-an-app-1
Adding Firebase to your Google Cloud project
To use Firebase authentication with your web service, add Firebase to your Google Cloud project and configure your authentication settings.
Add Firebase to your existing Google Cloud project using the Add project tool in the Firebase console.
Note that when you add Firebase to a Google Cloud project with billing enabled, you are required to confirm the Blaze billing plan for Firebase. However, web authentication is included for free on Firebase.
Enable the authentication sign-on providers in the Firebase console. For this web service, you will enable Email/Password and Google sign-in providers:
Click Develop > Authentication > Sign-in method.
Under Sign-in providers, hover the cursor over the Email/Password provider and click the pencil icon.
Toggle the Enable button to use Email/Password authentication.
After enabling the provider, click Save.
Do the same thing for the sign-in provider Google.
Tip: For more information about enabling other providers, see the "Before you begin" sections of the Facebook, Twitter, and GitHub guides on Firebase.
For Firebase to authenticate properly, your domain needs to be authorized for OAuth redirects. To authorize your domain, scroll down to Authorized Domains on the Sign-in method page, click Add Domain, and then enter the domain of your app on App Engine, excluding the
http://
prefix:GCP_PROJECT_ID.appspot.com
whereGCP_PROJECT_ID
is the ID of your Google Cloud project.
Adding Firebase to your web service
Now that Firebase is enabled in your Google Cloud project, you can add a Firebase to your web service using your Firebase project's custom code snippet, as well as Firebase JavaScript and CSS files.
To add Firebase to your web service, complete the following:
Go to the Firebase console and select your project.
From the project overview page, click Add Firebase to your web app to display the customized code snippet.
Click Copy.
Update your
templates/index.html
file by completing the following:Add your customized code snippet in the
<head>
tag of yourtemplates/index.html
file. For example, your custom code looks similar to this mock snippet:<!-- MOCK SNIPPET: DO NOT COPY --> <script src="https://www.gstatic.com/firebasejs/5.2.0/firebase.js"></script> <script> var config = { apiKey: "<API_KEY>", authDomain: "<PROJECT_ID>.firebaseapp.com", databaseURL: "https://<DATABASE_NAME>.firebaseio.com", projectId: "<PROJECT_ID>", storageBucket: "<BUCKET>.appspot.com", messagingSenderId: "<SENDER_ID>", }; firebase.initializeApp(config); </script>
Add the following lines in the
<head>
tag of yourtemplates/index.html
file to import the Firebase JavaScript and CSS files:Replace the current body of your
index.html
file with the following code, which you will use later in this guide to display authenticated user data:
Next Steps
Now that you've added Firebase to your Google Cloud project and your web service, you're ready to add code to your web service to enable it to authenticate users.