
准备工作
- 实验会创建一个 Google Cloud 项目和一些资源,供您使用限定的一段时间
- 实验有时间限制,并且没有暂停功能。如果您中途结束实验,则必须重新开始。
- 在屏幕左上角,点击开始实验即可开始
Configure the case study application
/ 50
Configure Identity Platform Authentication
/ 50
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.
In this lab, you perform the following tasks:
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources are made available to you.
This hands-on lab lets you do the lab activities in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
Click the Start Lab button. If you need to pay for the lab, a dialog opens for you to select your payment method. On the left is the Lab Details pane with the following:
Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).
The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
If necessary, copy the Username below and paste it into the Sign in dialog.
You can also find the Username in the Lab Details pane.
Click Next.
Copy the Password below and paste it into the Welcome dialog.
You can also find the Password in the Lab Details pane.
Click Next.
Click through the subsequent pages:
After a few moments, the Google Cloud console opens in this tab.
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. Cloud Shell provides command-line access to your Google Cloud resources.
Click Activate Cloud Shell at the top of the Google Cloud console.
Click through the following windows:
When you are connected, you are already authenticated, and the project is set to your Project_ID,
gcloud
is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
Output:
Output:
gcloud
, in Google Cloud, refer to the gcloud CLI overview guide.
From Cloud Shell toolbar, move Cloud Shell to a new window by clicking the Open in new window icon , then click Open Editor
icon to launch the code editor.
In the Cloud Shell terminal, run the following command to configure your Project ID, replacing <YOUR-PROJECT-ID>
with your lab Project ID:
Authorize Cloud Shell.
In this task, you clone, configure, and run the Quiz application.
Clone the application skeleton from a repository on GitHub.com:
Create a soft link as a shortcut to the working directory:
Navigate to the directory that contains the sample files for this lab:
Run the following command to change the region from us-central
to your default assigned region:
Configure the application:
This script file:
gs:[Project-ID]-media
.GCLOUD_PROJECT
and GCLOUD_BUCKET
.virtualenv
isolated Python environment for Python 3 and activates it.> pip install -r requirements.txt
.Click Check my progress to verify the objective.
Run the application:
Leave this window open because you need the Cloud Shell Web preview domain later in this lab.
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.
Navigate to the /firebase/start
folder using the file browser panel on the left side of the code editor.
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.
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.
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.
In this task, 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.
In the Google Cloud Console, on the Navigation menu (), click Identity Platform.
Click Enable Identity Platform.
The Identity Platform page appears in the Cloud Console.
Click Add a Provider.
In the Sign-in method window, for Select a provider, select Email / Password.
Click Enabled.
In the Authorized Domains pane, click Add Domain.
Return to the running Quiz Application and copy the domain which has the format below
Paste the domain into the Domain field.
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.
Click Save.
In the new identity provider window click Save.
You may need to scroll down to see the Save button.
In the Identity Platform pane, click Users.
Click Add User.
In the Add user dialog box, specify the following:
|
user1@example.com |
Password |
abc123! |
Click Add.
Click Check my progress to verify the objective.
In this task you apply your Identity Platform configuration to your client-side web application.
In the navigation pane, click Providers.
Click Application Setup Details.
In the Configure your application dialog box, copy the Identity Platform markup.
Click Close.
In the Cloud Shell code editor, open the index.html
file in ...webapp/static/client/
.
Paste the configuration markup just before the other <script></script>
tags at the bottom of the page.
Save the index.html
file.
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.
Return to the Quiz application and refresh your browser.
In the navigation bar, click Take Test.
In the navigation bar, click GCP, People, or Places.
In the navigation bar, enter the following invalid credentials:
|
user2@example.com |
Password |
abcd1234$ |
Click Login.
Enter the following credentials that you created in a previous task:
|
user1@example.com |
Password |
abc123! |
Click Login.
The user's email address should be shown in the navigation bar, and the first question will be presented.
In the navigation bar, click Logout.
Click the Register link.
In the new form, enter the following credentials:
|
user2@example.com |
Password |
abcd1234$ |
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.
In the navigation bar, click Logout.
In the Google Cloud Console, in the Identity Platform navigation pane, click Users.
In this lab, you learned how to use Identity Platform to enable email and password registration for your application.
Manual last updated November 13, 2024
Lab last tested November 13, 2024
Copyright 2025 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.
此内容目前不可用
一旦可用,我们会通过电子邮件告知您
太好了!
一旦可用,我们会通过电子邮件告知您
一次一个实验
确认结束所有现有实验并开始此实验