This tutorial shows you how to retrieve, verify, and store third-party credentials using Identity Platform, the App Engine standard environment, and Datastore.
This document walks you through a simple note-taking application called Firenotes that stores users' notes in their own personal notebooks. Notebooks are stored per user, and identified by each user's unique Identity Platform ID. The application has the following components:
The frontend configures the sign-in user interface and retrieves the Identity Platform ID. It also handles authentication state changes and lets users see their notes.
FirebaseUI is an open-source, drop-in solution that simplifies authentication and UI tasks. The SDK handles user login, linking multiple providers to one account, recovering passwords, and more. It implements authentication best practices for a smooth and secure sign-in experience.
The backend verifies the user's authentication state and returns user profile information as well as the user's notes.
The application stores user credentials in Datastore by using the NDB client library, but you can store the credentials in a database of your choice.
Firenotes is based on the Flask web application framework. The sample app uses Flask because of its simplicity and ease of use, but the concepts and technologies explored are applicable regardless of which framework you use.
By completing this tutorial, you'll accomplish the following:
This tutorial uses billable components of Google Cloud, including:
Use the Pricing Calculator
to generate a cost estimate based on your projected usage.
In the Google Cloud console, on the project selector page,
select or create a Google Cloud project. Roles required to select or create a project
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first
sign in to the gcloud CLI with your federated identity.
To initialize the gcloud CLI, run the following command:
In the Google Cloud console, on the project selector page,
select or create a Google Cloud project. Roles required to select or create a project
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first
sign in to the gcloud CLI with your federated identity.
To initialize the gcloud CLI, run the following command:
If you have already installed and initialized the SDK to a different project,
set the Before you begin
roles/resourcemanager.projectCreator), which contains the
resourcemanager.projects.create permission. Learn how to grant
roles.
gcloud init
roles/resourcemanager.projectCreator), which contains the
resourcemanager.projects.create permission. Learn how to grant
roles.
gcloud initgcloud project to the App Engine project ID you're using
for Firenotes. See Managing Google Cloud SDK Configurations for
specific commands to update a project with the gcloud tool.
To download the sample to your local machine:
Clone the sample application repository to your local machine:
git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git
Alternatively, you can download the sample as a zip file and extract it.
Navigate to the directory that contains the sample code:
cd python-docs-samples/appengine/standard/firebase/firenotes
To configure FirebaseUI for Identity Platform and enable identity providers:
Add Identity Platform to your app by following these steps:
Copy the application setup details into your Web Application.
Edit the backend/app.yaml file to add GOOGLE_CLOUD_PROJECT : 'PROJECT_ID' in the
env_variables section:
In the frontend/main.js file, configure the FirebaseUI login widget
by selecting which providers you want to offer your users.
In the Google Cloud console, enable the providers you chose to keep:
Add your domain to the list of authorized domains in Identity Platform:
Enter the domain of your app in the following format:
[PROJECT_ID].appspot.com
Don't include http:// before the domain name.
Navigate to the backend directory and complete the application setup:
cd backend/
Install the dependencies into a lib directory in your project:
pip install -t lib -r requirements.txt
In appengine_config.py, the vendor.add() method registers the libraries in
the lib directory.
To run the application locally, use the App Engine local development server:
Add the following URL as the backendHostURL in main.js:
http://localhost:8081
Navigate to the root directory of the application. Then, start the development server:
dev_appserver.py frontend/app.yaml backend/app.yaml
Visit http://localhost:8080/ in a web browser.
Now that you have set up a project and initialized an application for development, you can walk through the code to understand how to retrieve and verify Identity Platform ID tokens on the server.
The first step in server-side authentication is retrieving an access token to
verify. Authentication requests are handled with the onAuthStateChanged()
listener from Identity Platform:
When a user is signed in, the Identity Platform getToken() method in the
callback returns a Identity Platform ID token in the form of a JSON Web
Token (JWT).
After a user signs in, the frontend service fetches any existing notes in the
user's notebook through an AJAX GET request. This requires authorization to
access the user's data, so the JWT is sent in the Authorization header of the
request using the Bearer schema:
Before the client can access server data, your server must verify the token is
signed by Identity Platform. You can verify this token using the
Google Authentication Library for Python.
Use the authentication library's
verify_firebase_token
function to verify the bearer token and extract the claims:
Each identity provider sends a different set of claims, but each has at least a
sub claim with a unique user ID and a claim that provides some profile
information, such as name or email, that you can use to personalize the user
experience on your app.
After authenticating a user, you need to store their data for it to persist after a signed-in session has ended. The following sections explain how to store a note as a Datastore entity and segregate entities by user ID.
You can create an entity in Datastore by declaring an
NDB model class with
certain properties such as integers or strings. Datastore indexes
entities by kind; in the case of Firenotes, the kind of each entity is Note.
For querying purposes, each Note is stored with a key name, which is the
user ID obtained from the sub claim in the previous section.
The following code demonstrates how to set properties of an entity, both with the constructor method for the model class when the entity is created and through assignment of individual properties after creation:
To write the newly created Note to Datastore, call the put()
method on the note object.
To retrieve user data associated with a particular user ID, use the NDB
query() method to search the database for notes in the same entity group.
Entities in the same group, or
ancestor path,
share a common key name, which in this case is the user ID.
You can then fetch the query data and display the notes in the client:
You have successfully integrated Identity Platform with your App Engine application. To see your application running in a live production environment:
main.js to
https://backend-dot-[PROJECT_ID].appspot.com. Replace [PROJECT_ID] with
your project ID.Deploy the application using the Google Cloud SDK command-line interface:
gcloud app deploy backend/index.yaml frontend/app.yaml backend/app.yaml
View the application live at https://[PROJECT_ID].appspot.com.
To avoid incurring charges to your Google Cloud account for the resources used in this tutorial, delete your App Engine project:
The easiest way to eliminate billing is to delete the project that you created for the tutorial.
To delete the project:
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 2026-06-11 UTC.