Lab setup instructions and requirements
Protect your account and progress. Always use a private browser window and lab credentials to run this lab.

App Dev - Adding User Authentication to your Application: Python

Lab 2 год universal_currency_alt 5 кредитів show_chart Поглиблений
info This lab may incorporate AI tools to support your learning.
This content is not yet optimized for mobile devices.
For the best experience, please visit us on a desktop computer using a link sent by email.

Overview

This lab shows how to add authentication to your application using Identity Platform. This authorization identifies who you are, and determines what you can do. For more information, see Authentication Overview.

Identity Platform provides a drop-in, customizable authentication service for user sign-up and sign-in. Development and admin activities are made easier with a range of app SDKs (Android, iOS, and web) as well as admin SDKs (Node.js, Java, Python, and more). For more information about Identity Platform, see Identity Platform.

The application used in this lab is an online Quiz application. You add Identity Platform authentication, and then configure authentication to use a simple email address and password credential. Finally you ensure that users must register and log in before taking a quiz.

Objectives

In this lab, you perform the following tasks:

  • Add Identity Platform configuration to a client-side web application
  • Write Python code to integrate Identity Platform Authentication into a client-side web application

Setup and requirements

For each lab, you get a new Google Cloud project and set of resources for a fixed time at no cost.

  1. Make sure you signed into Google Skills using an incognito window.

  2. Note the lab's access time (for example, 02:00:00 and make sure you can finish in that time block.

Note: There is no pause feature. You can restart if needed, but you have to start at the beginning.
  1. When ready, click Start Lab.

  2. Note your lab credentials. You will use them to sign in to Google Cloud Console. Credentials pane

  3. Click Open Google Console.

  4. Click Use another account and copy/paste credentials for this lab into the prompts.

Note: If you use other credentials, you'll get errors or incur charges.
  1. Accept the terms and skip the recovery resource page.
Note: Do not click End Lab unless you are finished with the lab or want to restart it. This clears your work and removes the project.

Activate Google Cloud Shell

Google Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud.

Google Cloud Shell provides command-line access to your Google Cloud resources.

  1. In Cloud console, on the top right toolbar, click the Open Cloud Shell button.

    Highlighted Cloud Shell icon

  2. Click Continue.

It takes a few moments to provision and connect to the environment. When you are connected, you are already authenticated, and the project is set to your PROJECT_ID. For example:

Project ID highlighted in the Cloud Shell Terminal

gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.

  • You can list the active account name with this command:
gcloud auth list

Output:

Credentialed accounts: - @.com (active)

Example output:

Credentialed accounts: - google1623327_student@qwiklabs.net
  • You can list the project ID with this command:
gcloud config list project

Output:

[core] project =

Example output:

[core] project = qwiklabs-gcp-44776a13dea667a6 Note: Full documentation of gcloud is available in the gcloud CLI overview guide .

Task 1. Prepare the case study application

In this task, you clone, configure, and run the Quiz application.

Clone source code in Cloud Shell

  1. Clone the application skeleton from a repository on GitHub.com:

    git clone https://github.com/GoogleCloudPlatform/training-data-analyst
  2. Create a soft link as a shortcut to the working directory:

    ln -s ~/training-data-analyst/courses/developingapps/v1.3/python/firebase ~/firebase

Configure and run the case study application

  1. Navigate to the directory that contains the sample files for this lab:

    cd ~/firebase/start
  2. Update the App Engine region using the sed command.

    export REGION={{{project_0.startup_script.app_region|REGION}}} sed -i "s/us-central/$REGION/g" prepare_environment.sh
  3. Configure the application:

    . prepare_environment.sh

    This script file:

    • Creates an App Engine application.
    • Creates a Cloud Storage bucket named gs:[Project-ID]-media.
    • Exports two environment variables: GCLOUD_PROJECT and GCLOUD_BUCKET.
    • Creates a virtualenv isolated Python environment for Python 3 and activates it.
    • Runs > pip install -r requirements.txt.
    • Creates entities in Cloud Datastore.
    • Prints out the Google Cloud Platform Project ID.
  4. Run the application:

    python run_server.py

Start the case study application

  • In Cloud Shell, click Web preview (Web Preview icon) > Preview on port 8080 to preview the Quiz application.

Leave this window open for now, because you will need the Cloud Shell Web preview domain (which is in the form: 8080-27542cac-44d0-41a9-9e96-065800c2100c.ql-europe-west1-ctgq.cloudshell.dev) later in this lab.

Task 2. Examine the case study application code

In this task you examine the case study application code. You can use the shell editors that are installed on Cloud Shell, such as nano or vim or the Cloud Shell code editor.

This lab uses the Cloud Shell code editor to review the Quiz application code.

Launch the Cloud Shell code editor

  • From Cloud Shell, click Open Editor to launch the code editor.

Open Editor button

Note: If necessary, click Open in a new window. You can switch back to terminal with Open Terminal.

Review the client application

  1. Navigate to the /firebase/start folder using the file browser panel on the left side of the code editor.

  2. Continue navigating. Open ...quiz/webapp/static/client/. Click on the index.html file.

    This file is the single page in the AngularJS Single Page Application (SPA). It contains <script></script> tags for the application libraries and code, and markup where the SPA will render dynamic output.

  3. Select the qiq-login-template.html file in the ...quiz/webapp/static/client/app/auth/ folder.

    This file contains the AngularJS template for the Login component. Notice how it contains a couple of textboxes and a button. The button has an event handler that runs code when it is clicked.

  4. Still in this folder, select the qiq-login.js file.

    This file contains an AngularJS component. It allows the user to log in to the application or to navigate to a registration page.

Task 3. Configure Identity Platform Authentication

In this task you confirm that billing is enabled for your cloud project. Next, you configure Identity Platform to sign in a user with an email and password. You then create a user which you can use to login to the Quiz Application.

Confirm that billing is enabled

  1. In the Google Cloud Console, on the Navigation menu (Navigation menu icon), click Billing.

  2. Verify that a Billing account is linked to the project. You should see a message stating that the Billing account "Qwiklabs Production gcpd xx" is linked to this project.

Configure Identity Platform for email and password

  1. In the Google Cloud Console, on the Navigation menu (Navigation menu icon), click View all Products, then search and click Identity Platform.

  2. Click Enable Identity Platform.

    Note: If you see the Leave site pop-up message, click Leave.

    The Identity Platform page appears in the Cloud Console.

    The Add a Provider button.

  3. Click Add a Provider.

  4. In the Sign-in method window, for Select a provider, select Email / Password.

  5. Click Enabled.

  6. In the Authorized Domains pane, click Add Domain.

  7. Return to the running Quiz Application and copy the domain (which has the format 8080-27542cac-44d0-41a9-9e96-065800c2100c.ql-europe-west1-ctgq.cloudshell.dev).

Add authorized domain dialog box

  1. Paste the domain into the Domain field.

  2. Modify the pasted domain so that only the domain name is in the Domain field.

    You should remove https:// and anything that follows the domain name, including slashes. The domain name should end with cloudshell.dev.

  3. Click Save.

Note: If you receive an error message indicating that you should try again later, you probably submitted more than just the domain name. You should click Cancel in the dialog box and then click Add Domain to try again.
  1. In the new identity provider window click Save.

    You may need to scroll down to see the Save button.

Add a user

  1. In the Identity Platform pane, click Users.

  2. Click Add User.

  3. In the Add user dialog box, specify the following:

    Email

    user1@example.com

    Password

    abc123!

  4. Click Add.

Task 4. Integrate a client-side web application with Identity Platform

In this task you apply the your Identity Platform configuration to your client-side web application.

  1. In the navigation pane, click Providers.

  2. Click Application Setup Details.

  3. In the Configure your application dialog box, copy the Identity Platform markup.

    The highlighted Copy icon

  4. Click Close.

  5. In the Cloud Shell code editor, open the index.html file in ...webapp/static/client/.

  6. Paste the configuration markup just before the other <script></script> tags at the bottom of the page.

  7. Save the index.html file.

Task 5. Run the application

In this task you verify that you can login to the Quiz Application using the credentials you created in Identity Platform in a previous step. You then register a new user in the Quiz Application and verify that these credentials are added to Identity Platform.

  1. Return to the Quiz application and refresh your browser.

  2. In the navigation bar, click Take Test.

    The Quite Interesting Quiz page.

  3. In the navigation bar, click GCP, People, or Places.

    Note: You should not be able to take a test without being logged in.
  4. In the navigation bar, enter the following invalid credentials:

    Email

    user2@example.com

    Password

    abcd1234$

  5. Click Login.

    Note: Login will fail because the user is not registered.
  6. Enter the following credentials that you created in a previous task:

    Email

    user1@example.com

    Password

    abc123!

  7. Click Login.

    The user's email address should be shown in the navigation bar, and the first question will be presented.

    Note: If the login does not work, the password may not have been configured correctly. Return to the Users page in Identity Platform and delete user1@example.com, and then add user1@example.com with the correct password.
  8. In the navigation bar, click Logout.

  9. Click the Register link.

  10. In the new form, enter the following credentials:

    Email

    user2@example.com

    Password

    abcd1234$

  11. Click Register.

    A complex password is required. If you have entered an acceptable password, you should be logged in and redirected to the GCP quiz.

    You are able to answer questions and submit answers.

  12. In the navigation bar, click Logout.

    Note: You will be logged out and redirected to the Quiz homepage.
  13. In the Google Cloud Console, in the Identity Platform navigation pane, click Users.

    Note: You should see user2@example.com has been added as a user.

Congratulations!

In this lab, you learned how to use Identity Platform to enable email and password registration for your application.

End your lab

When you have completed your lab, click End Lab. Google Skills removes the resources you’ve used and cleans the account for you.

You will be given an opportunity to rate the lab experience. Select the applicable number of stars, type a comment, and then click Submit.

The number of stars indicates the following:

  • 1 star = Very dissatisfied
  • 2 stars = Dissatisfied
  • 3 stars = Neutral
  • 4 stars = Satisfied
  • 5 stars = Very satisfied

You can close the dialog box if you don't want to provide feedback.

For feedback, suggestions, or corrections, please use the Support tab.

Copyright 2026 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.

Before you begin

  1. Labs create a Google Cloud project and resources for a fixed time
  2. Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
  3. On the top left of your screen, click Start lab to begin

Use private browsing

  1. Copy the provided Username and Password for the lab
  2. Click Open console in private mode

Sign in to the Console

  1. Sign in using your lab credentials. Using other credentials might cause errors or incur charges.
  2. Accept the terms, and skip the recovery resource page
  3. Don't click End lab unless you've finished the lab or want to restart it, as it will clear your work and remove the project

This content is not currently available

We will notify you via email when it becomes available

Great!

We will contact you via email if it becomes available

One lab at a time

Confirm to end all existing labs and start this one

Use private browsing to run the lab

Using an Incognito or private browser window is the best way to run this lab. This prevents any conflicts between your personal account and the Student account, which may cause extra charges incurred to your personal account.