Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit 5772563

Browse files
committed
refactor WebApp step 2 user management to remove CloudFormation and change s3 to be Amplify Console + git steps
1 parent e97092a commit 5772563

File tree

2 files changed

+37
-266
lines changed

2 files changed

+37
-266
lines changed
Lines changed: 37 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,6 @@
11
# Module 2: User Authentication and Registration with Amazon Cognito User Pools
22

3-
In this module you'll create an Amazon Cognito user pool to manage your users' accounts. You'll deploy pages that enable customers to register as a new user, verify their email address, and sign into the site.
4-
5-
If you want to skip ahead to the next module, you can launch one of these AWS CloudFormation templates in the Region of your choice in order to build the necessary resources automatically.
6-
7-
Region| Launch
8-
------|-----
9-
US East (N. Virginia) | [![Launch Module 2 in us-east-1](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/images/cloudformation-launch-stack-button.png)](https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?stackName=wildrydes-webapp-2&templateURL=https://s3.amazonaws.com/wildrydes-us-east-1/WebApplication/2_UserManagement/user-management.yaml)
10-
US East (Ohio) | [![Launch Module 2 in us-east-2](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/images/cloudformation-launch-stack-button.png)](https://console.aws.amazon.com/cloudformation/home?region=us-east-2#/stacks/new?stackName=wildrydes-webapp-2&templateURL=https://s3.amazonaws.com/wildrydes-us-east-2/WebApplication/2_UserManagement/user-management.yaml)
11-
US West (Oregon) | [![Launch Module 2 in us-west-2](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/images/cloudformation-launch-stack-button.png)](https://console.aws.amazon.com/cloudformation/home?region=us-west-2#/stacks/new?stackName=wildrydes-webapp-2&templateURL=https://s3.amazonaws.com/wildrydes-us-west-2/WebApplication/2_UserManagement/user-management.yaml)
12-
EU (Frankfurt) | [![Launch Module 2 in eu-central-1](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/images/cloudformation-launch-stack-button.png)](https://console.aws.amazon.com/cloudformation/home?region=eu-central-1#/stacks/new?stackName=wildrydes-webapp-2&templateURL=https://s3.amazonaws.com/wildrydes-eu-central-1/WebApplication/2_UserManagement/user-management.yaml)
13-
EU (Ireland) | [![Launch Module 2 in eu-west-1](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/images/cloudformation-launch-stack-button.png)](https://console.aws.amazon.com/cloudformation/home?region=eu-west-1#/stacks/new?stackName=wildrydes-webapp-2&templateURL=https://s3.amazonaws.com/wildrydes-eu-west-1/WebApplication/2_UserManagement/user-management.yaml)
14-
EU (London) | [![Launch Module 2 in eu-west-2](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/images/cloudformation-launch-stack-button.png)](https://console.aws.amazon.com/cloudformation/home?region=eu-west-2#/stacks/new?stackName=wildrydes-webapp-2&templateURL=https://s3.amazonaws.com/wildrydes-eu-west-2/WebApplication/2_UserManagement/user-management.yaml)
15-
Asia Pacific (Tokyo) | [![Launch Module 2 in ap-northeast-1](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/images/cloudformation-launch-stack-button.png)](https://console.aws.amazon.com/cloudformation/home?region=ap-northeast-1#/stacks/new?stackName=wildrydes-webapp-2&templateURL=https://s3.amazonaws.com/wildrydes-ap-northeast-1/WebApplication/2_UserManagement/user-management.yaml)
16-
Asia Pacific (Seoul) | [![Launch Module 2 in ap-northeast-2](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/images/cloudformation-launch-stack-button.png)](https://console.aws.amazon.com/cloudformation/home?region=ap-northeast-2#/stacks/new?stackName=wildrydes-webapp-2&templateURL=https://s3.amazonaws.com/wildrydes-ap-northeast-2/WebApplication/2_UserManagement/user-management.yaml)
17-
Asia Pacific (Sydney) | [![Launch Module 2 in ap-southeast-2](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/images/cloudformation-launch-stack-button.png)](https://console.aws.amazon.com/cloudformation/home?region=ap-southeast-2#/stacks/new?stackName=wildrydes-webapp-2&templateURL=https://s3.amazonaws.com/wildrydes-ap-southeast-2/WebApplication/2_UserManagement/user-management.yaml)
18-
Asia Pacific (Mumbai) | [![Launch Module 2 in ap-south-1](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/images/cloudformation-launch-stack-button.png)](https://console.aws.amazon.com/cloudformation/home?region=ap-south-1#/stacks/new?stackName=wildrydes-webapp-2&templateURL=https://s3.amazonaws.com/wildrydes-ap-south-1/WebApplication/2_UserManagement/user-management.yaml)
19-
20-
<details>
21-
<summary><strong>CloudFormation Launch Instructions (expand for details)</strong></summary><p>
22-
23-
1. Choose the **Launch Stack** link above for the region of your choice.
24-
25-
1. Choose **Next** on the Select Template page.
26-
27-
1. Provide the name of your website bucket from module 1 for the **Website Bucket Name** (e.g. `wildrydes-yourname`) and choose **Next**.
28-
29-
**Note:** You must specify the same bucket name you used in the previous module. If you provide a bucket name that does not exist or that you do not have write access to, the CloudFormation stack will fail during creation.
30-
31-
![Speficy Details Screenshot](../images/module2-cfn-specify-details.png)
32-
33-
1. On the Options page, leave all the defaults and choose **Next**.
34-
35-
1. On the Review page, check the box to acknowledge that CloudFormation will create IAM resources and choose **Create**.
36-
![Acknowledge IAM Screenshot](../images/cfn-ack-iam.png)
37-
38-
This template uses custom resources to create an Amazon Cognito user pool and client as well as generate a configuration file with the details needed to connect to this user pool and upload it to your website bucket. The template will create a role that provides access for creating these resources and uploading the config file to your bucket.
39-
40-
1. Wait for the `wildrydes-webapp-2` stack to reach a status of `CREATE_COMPLETE`.
41-
42-
1. Follow the steps outlined in the [Implementation Verification](#implementation-verification) section to confirm you are ready to move on to the next module.
43-
44-
</p></details>
3+
In this module you'll create an [Amazon Cognito][cognito] user pool to manage your users' accounts. You'll deploy pages that enable customers to register as a new user, verify their email address, and sign into the site.
454

465
## Architecture Overview
476

@@ -55,75 +14,49 @@ After users have a confirmed account (either using the email verification proces
5514

5615
## Implementation Instructions
5716

58-
Each of the following sections provides an implementation overview and detailed, step-by-step instructions. The overview should provide enough context for you to complete the implementation if you're already familiar with the AWS Management Console or you want to explore the services yourself without following a walkthrough.
17+
:heavy_exclamation_mark: Ensure you've completed the [Static Web hosting][static-web-hosting] step before beginning
18+
the workshop.
5919

60-
If you're using the latest version of the Chrome, Firefox, or Safari web browsers the step-by-step instructions won't be visible until you expand the section.
20+
Each of the following sections provides an implementation overview and detailed, step-by-step instructions. The overview should provide enough context for you to complete the implementation if you're already familiar with the AWS Management Console or you want to explore the services yourself without following a walkthrough.
6121

6222
### 1. Create an Amazon Cognito User Pool
6323

6424
#### Background
6525

6626
Amazon Cognito provides two different mechanisms for authenticating users. You can use Cognito User Pools to add sign-up and sign-in functionality to your application or use Cognito Identity Pools to authenticate users through social identity providers such as Facebook, Twitter, or Amazon, with SAML identity solutions, or by using your own identity system. For this module you'll use a user pool as the backend for the provided registration and sign-in pages.
6727

68-
#### High-Level Instructions
69-
7028
Use the Amazon Cognito console to create a new user pool using the default settings. Once your pool is created, note the Pool Id. You'll use this value in a later section.
7129

72-
<details>
73-
<summary><strong>Step-by-step instructions (expand for details)</strong></summary><p>
74-
75-
1. From the AWS Console click **Services** then select **Cognito** under Security, Identity & Compliance.
30+
**:white_check_mark: Step-by-step directions**
7631

32+
1. Go to the [Amazon Cognito Console][cognito-console]
7733
1. Choose **Manage your User Pools**.
78-
7934
1. Choose **Create a User Pool**
80-
8135
1. Provide a name for your user pool such as `WildRydes`, then select **Review Defaults**
82-
8336
![Create a user pool screenshot](../images/create-a-user-pool.png)
84-
8537
1. On the review page, click **Create pool**.
86-
8738
1. Note the **Pool Id** on the Pool details page of your newly created user pool.
8839

89-
</p></details>
90-
9140
### 2. Add an App Client to Your User Pool
9241

9342
From the Amazon Cognito console select your user pool and then select the **App clients** section. Add a new app and make sure the Generate client secret option is deselected. Client secrets aren't supported with the JavaScript SDK. If you do create an app with a generated secret, delete it and create a new one with the correct configuration.
9443

95-
<details>
96-
<summary><strong>Step-by-step instructions (expand for details)</strong></summary><p>
97-
44+
**:white_check_mark: Step-by-step directions**
9845
1. From the Pool Details page for your user pool, select **App clients** from the **General settings** section in the left navigation bar.
99-
10046
1. Choose **Add an app client**.
101-
10247
1. Give the app client a name such as `WildRydesWebApp`.
103-
10448
1. **Uncheck** the Generate client secret option. Client secrets aren't supported for use with browser-based applications.
105-
10649
1. Choose **Create app client**.
107-
10850
<kbd>![Create app client screenshot](../images/add-app.png)</kbd>
109-
11051
1. Note the **App client id** for the newly created application.
11152

112-
</p></details>
113-
114-
### 3. Update the config.js File in Your Website Bucket
115-
116-
The [/js/config.js](../1_StaticWebHosting/website/js/config.js) file contains settings for the user pool ID, app client ID and Region. Update this file with the settings from the user pool and app you created in the previous steps and upload the file back to your bucket.
53+
### 3. Update the config.js File in Your Website
11754

118-
<details>
119-
<summary><strong>Step-by-step instructions (expand for details)</strong></summary><p>
120-
121-
1. Download the [config.js](../1_StaticWebHosting/website/js/config.js) file from the website directory of the first module in this repository to your local machine.
122-
123-
1. Open the downloaded file using the text editor of your choice.
55+
The [/js/config.js][configjs] file contains settings for the user pool ID, app client ID and Region. Update this file with the settings from the user pool and app you created in the previous steps and commit the file back to your git repository.
12456

57+
**:white_check_mark: Step-by-step directions**
58+
1. On your Cloud9 development environment open `js/config.js`
12559
1. Update the `cognito` section with the correct values for the user pool and app you just created.
126-
12760
You can find the value for `userPoolId` on the Pool details page of the Amazon Cognito console after you select the user pool that you created.
12861

12962
![Pool ID](../images/pool-id.png)
@@ -143,38 +76,32 @@ The [/js/config.js](../1_StaticWebHosting/website/js/config.js) file contains se
14376
region: 'us-west-2' // e.g. us-east-2
14477
},
14578
api: {
146-
invokeUrl: '' // e.g. https://rc7nyt4tql.execute-api.us-west-2.amazonaws.com/prod',
79+
invokeUrl: '' // e.g. https://rc7nyt4tql.execute-api.us-west-2.amazonaws.com/prod,
14780
}
14881
};
14982
```
150-
15183
1. Save the modified file making sure the filename is still `config.js`.
84+
1. Commit the changes to your git repository:
85+
```
86+
$ git add js/config.js
87+
$ git commit -m "configure cognito"
88+
$ git push
89+
...
90+
Counting objects: 4, done.
91+
Compressing objects: 100% (4/4), done.
92+
Writing objects: 100% (4/4), 415 bytes | 415.00 KiB/s, done.
93+
Total 4 (delta 3), reused 0 (delta 0)
94+
To https://git-codecommit.us-east-1.amazonaws.com/v1/repos/wildrydes-site
95+
7668ed4..683e884 master -> master
96+
```
15297

153-
1. Open the Amazon S3 console by visiting [https://console.aws.amazon.com/s3/](https://console.aws.amazon.com/s3/).
154-
155-
1. Select your Wild Rydes website bucket that you created in the previous module.
156-
157-
1. Browse to the `js` prefix.
158-
159-
1. Choose **Upload**, then **Add Files**.
160-
161-
1. Browse to the directory where you saved your locally modified version of the config.js file, select it, and choose **Open**.
162-
163-
![s3-upload.png](../images/s3-upload.png)
164-
165-
1. Choose **Upload** on the left side of the dialog.
166-
167-
</p></details>
168-
169-
<p>
98+
Amplify Console should pick up the changes and begin building and deploying your web application.
17099

171100
**Note:** Instead of having you write the browser-side code for managing the registration, verification, and sign in flows, we provide a working implementation in the assets you deployed in the first module. The [cognito-auth.js](../1_StaticWebHosting/website/js/cognito-auth.js) file contains the code that handles UI events and invokes the appropriate Amazon Cognito Identity SDK methods. For more information about the SDK, see the [project page on GitHub](https://github.com/aws/amazon-cognito-identity-js).
172101

173-
</p>
174-
175102
## Implementation Validation
176103

177-
1. Visit `/register.html` under your website domain, or choose the **Giddy Up!** button on the homepage of your site.
104+
1. Visit `register.html` under your website domain, or choose the **Giddy Up!** button on the homepage of your site.
178105

179106
1. Complete the registration form and choose **Let's Ryde**. You can use your own email or enter a fake email. Make sure to choose a password that contains at least one upper-case letter, a number, and a special character. Don't forget the password you entered for later. You should see an alert that confirms that your user has been created.
180107

@@ -196,9 +123,17 @@ The [/js/config.js](../1_StaticWebHosting/website/js/config.js) file contains se
196123

197124
![Successful login screenshot](../images/successful-login.png)
198125

199-
After you have successfully logged into your web application, you can proceed to the next module, [Serverless Backend](../3_ServerlessBackend).
126+
After you have successfully logged into your web application, you can proceed to the next module, [Serverless Backend][serverless-backend].
200127

201128
### Extra
202129

203-
* Try copying the **auth_token** you've received and paste that into an [online JWT Decoder](https://jwt.io/) to understand what this token means for your application
130+
* Try copying the **auth_token** you've received and paste that into an [online JWT Decoder][jwt-decoder] to understand what this token means for your application
204131
132+
[static-web-hosting]: ../1_StaticWebHosting/
133+
[amplify-console]: https://aws.amazon.com/amplify/console/
134+
[cognito]: https://aws.amazon.com/cognito/
135+
[setup]: ../0_Setup/
136+
[serverless-backend]: ../3_ServerlessBackend/
137+
[cognito-console]: https://console.aws.amazon.com/cognito/home
138+
[configjs]: ../1_StaticWebHosting/website/js/config.js
139+
[jwt-decoder]: https://jwt.io/

WebApplication/2_UserManagement/user-management.yaml

Lines changed: 0 additions & 164 deletions
This file was deleted.

0 commit comments

Comments
 (0)