Stay organized with collections Save and categorize content based on your preferences.
Region IDThe REGION_ID
is an abbreviated code that Google assigns based on the region you select when you create your app. The code does not correspond to a country or province, even though some region IDs may appear similar to commonly used country and province codes. For apps created after February 2020, REGION_ID.r
is included in App Engine URLs. For existing apps created before this date, the region ID is optional in the URL.
Learn more about region IDs.
Note: If you are deploying a new Python web service to Google Cloud, we recommend getting started with Cloud Run.Add a user sign-in flow to your web service that uses Firebase Authentication.
In this step of the guide, you update your web service to authenticate users and to retrieve and display a user's own information after they authenticate. Note that, for this step, the site request times will still be global rather than user-specific.
Before you beginIf you have completed all the previous steps in this guide, skip this section. Otherwise, complete one of the following:
Start from Build a Python 3 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 and adding Firebase:
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_python3/building-an-app/building-an-app-2
Firebase provides JavaScript methods and variables that you can use to configure sign-in behavior for your web service. For this web service, add a sign out function, a variable that configures the sign in UI, and a function controlling what changes when a user signs in or out.
To add the behaviors required for an authentication flow, replace your static/script.js
file's current event listener method with the following code:
Notice that the onAuthStateChanged()
method, which controls what changes when a user signs in or out, stores the user's ID token as a cookie. This ID token is a unique token that Firebase generates automatically when a user successfully signs in, and is used by the server to authenticate the user.
Next, verify users on the server using their unique Firebase ID token, then decrypt their token so that you can print their data back to them.
To use the Firebase ID token:
Retrieve, verify, and decrypt the token in the root
method of your main.py
file:
request
from Flask so that you can fetch the cookie containing the user's ID token.Ensure that your requirements.txt
file includes all necessary dependencies:
Test your web service by running it locally in a virtual environment:
Run the following commands in your project's main directory to install new dependencies and run your web service. If you have not set up a virtual enviornment for local testing, see testing your web service.
pip install -r requirements.txt
python main.py
Enter the following address in your web browser to view your web service:
http://localhost:8080
localhost
URL rather than the full IP address of your local host or you will get an authentication error. This is because your local host's IP address is not listed as an authorized domain in your Firebase project. Deploy your web service
Now that you have authentication working locally, you can re-deploy your web service to App Engine.
Run the following command from the root directory of your project, where your app.yaml
file is located:
gcloud app deploy
All traffic is automatically routed to the new version you deployed.
For more information on managing versions, see Managing Services and Versions.
View your serviceTo quickly launch your browser and access your web service at https://PROJECT_ID.REGION_ID.r.appspot.com
, run the following command:
gcloud app browse
Next steps
Now that you've set up user authentication, you're ready to learn how to update your web service to personalize data for authenticated users.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-07 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["The `REGION_ID` 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, and is optional for apps created before that date."],["This guide outlines how to add a user sign-in flow to a Python web service using Firebase Authentication, enabling users to authenticate and view their information."],["Firebase provides JavaScript methods and variables to configure sign-in behaviors, including sign-out functionality and a variable for the sign-in UI, managing the visual changes based on user authentication status."],["The process includes retrieving, verifying, and decrypting a unique Firebase ID token on the server side, using this token to authenticate users and access their data."],["After local testing with Firebase, you can redeploy the web service to App Engine, making the updated version live, and then use the gcloud app browse command to view it."]]],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4