You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 14, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: Auth/0_GettingStarted/README.md
+5-8Lines changed: 5 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,8 +6,7 @@ This section outlines the prerequisites to complete the workshop and instruction
6
6
7
7
### AWS Account
8
8
9
-
In order to complete this workshop, you'll need an AWS account and access to
10
-
create and manage the AWS services that are used in this workshop, including Cloud9, Cognito, API Gateway, Lambda, and DynamoDB.
9
+
In order to complete this workshop, you'll need an AWS account and access to create and manage the AWS services that are used in this workshop, including Cloud9, Cognito, API Gateway, Lambda, DynamoDB, and IAM policies and roles.
11
10
12
11
The code and instructions in this workshop assume only one participant is using a given AWS account at a time. If you attempt sharing an account with another participant, you will encounter naming conflicts for certain resources. You can work around this by using distinct Regions, but the instructions do not provide details on the changes required to make this work.
13
12
@@ -26,8 +25,6 @@ for popular programming languages and the AWS Command Line Interface (CLI)
26
25
pre-installed so you don’t need to install files or configure your laptop for
27
26
this workshop.
28
27
29
-
In this workshop, you will use a Cloud9 environment which will have access to the same AWS resources as the user with which you logged into the AWS Management Console.
30
-
31
28
## Cloud9 IDE Setup
32
29
33
30
In this section you will launch a CloudFormation stack that will create a a new [Amazon VPC](https://aws.amazon.com/vpc/) environment and a [Cloud9 IDE](https://aws.amazon.com/cloud9/) Instance that you will use in the rest of the workshop.
@@ -53,9 +50,9 @@ Asia Pacific (Sydney) | [ role from within the application.
5
5
6
6
Since Wild Rydes is a ride sharing application, a key requirement is that all users must sign-up and sign-in before they're allowed to request a ride. You will configure the application to integrate with [Amazon Cognito](https://aws.amazon.com/cognito/) for these purposes via the [AWS Amplify JavaScript library](https://aws-amplify.github.io/).
@@ -15,13 +15,13 @@ For this module, we will be creating a Cognito User Pool as our secure user dire
15
15
16
16
## Implementation Overview
17
17
18
-
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.
18
+
Each of the following sections provides an implementation overview and detailed, step-by-step instructions. The overview should provide context for you to complete the implementation yourself if you're comfortable with the AWS Management Console and are comfortable exploring the services and documentation yourself without following a walkthrough.
19
19
20
20
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.
21
21
22
22
### 1. Running the website locally
23
23
24
-
1. From your Cloud9 workspace, select the terminal window and when you are within your website directory, run the following command to start the local web server
24
+
1. From your Cloud9 workspace, select the terminal window and when you are within your `~/environment/aws-serverless-workshops/Auth/website` directory, run the following command to start the local web server
25
25
26
26
```console
27
27
yarn start
@@ -30,7 +30,7 @@ If you're using the latest version of the Chrome, Firefox, or Safari web browser
30
30
Wait for the development server to start. You can ignore any message saying *Compiled with warnings* as we will resolve these warnings as we add our functionality to the application.
31
31
32
32
33
-
2. Now that the development server has started, click **Preview** in the top of the screen next to the Run button.
33
+
2. Now that the development server has started, click **Preview Running Application** in the top of the screen next to the Run button.
@@ -44,12 +44,14 @@ If you're using the latest version of the Chrome, Firefox, or Safari web browser
44
44
45
45
### 2. Creating a Cognito User Pool
46
46
47
-
Amazon Cognito lets you add user sign-up, sign-in, and access control to your web and mobile apps quickly and easily. In this step, we'll create a Cognito user pool for use with our Wild Rydes app.
47
+
Amazon Cognito lets you add user sign-up, sign-in, and access control to your web and mobile apps quickly and easily. In this step, we'll create a Cognito user pool for our Wild Rydes app.
48
48
49
49
#### High-Level Instructions
50
50
51
51
Use the AWS console to create an Amazon Cognito User Pool requiring e-mail verification.
52
52
53
+
**Note**: The console's region will default to the last region you were using previously. Change this to the same region where you launched your CloudFormation pre-requisite stack.
54
+
53
55
<details>
54
56
<summary><strong>Step-by-step instructions (expand for details)</strong></summary><p>
55
57
@@ -67,23 +69,23 @@ Use the AWS console to create an Amazon Cognito User Pool requiring e-mail verif
67
69
68
70

69
71
70
-
7. Leave **Username** selected, but additionally select *Also allow sign in with verified email address* and *Also allow sign in with verified phone number*.
72
+
7. Leave **Username** selected, but additionally select **Also allow sign in with verified email address** and **Also allow sign in with verified phone number**.
71
73
72
74
8. Leave all other attribute defaults as-is.
73
75
74
-
9. Choose **Next**.
76
+
9. Choose **Next step**.
75
77
76
78

77
79
78
-
10. Leave password policies and user sign up settings set to default settings and choose **Next**.
80
+
10. Leave password policies and user sign up settings set to default settings and choose **Next step**.
79
81
80
82

81
83
82
-
11. Leave MFA set to Off for this workshop.
84
+
11. Leave **MFA set to Off** for this workshop.
83
85
84
86
12. Leave the default setting selected of requiring e-mail verification.
85
87
86
-
13. Choose **Save changes**.
88
+
13. Choose **Next step**.
87
89
88
90

89
91
@@ -95,7 +97,7 @@ Use the AWS console to create an Amazon Cognito User Pool requiring e-mail verif
95
97
96
98

97
99
98
-
17. Choose **Add an app client**.
100
+
17. In the next screen, click the **Add an app client** link.
99
101
100
102
18. Input `wildrydes-web-app` as the app client name.
101
103
@@ -113,21 +115,27 @@ Use the AWS console to create an Amazon Cognito User Pool requiring e-mail verif
113
115
114
116
24. Review summary of all provided settings for accuracy then choose **Create pool**.
115
117
118
+

119
+
116
120
25. Within Cloud9, click the **+** symbol and choose to create **New File**. You will use this new blank editor tab as a scratchpad for various resource names and variables.
26. Back in the AWS Cognito console, copy your new **User Pool Id** into the scratchpad tab.
121
125
126
+

127
+
122
128
27. Choose **App clients** heading under **General settings** within the Cognito navigation panel.
123
129
124
130
28. Copy the **App client ID** over to your scrathpad. You will be using both of these values later on.
125
131
132
+

133
+
126
134
</p></details>
127
135
128
136
### 3. Creating a Cognito Identity Pool
129
137
130
-
Cognito Identity Pools are used to provide AWS credentials via IAM roles to end-user applications. Since we'll be using IAM integration to integrate our Cognito deployment and users with other AWS services, we'll go ahead and create this identity pool now.
138
+
Cognito Identity Pools are used to provide AWS credentials via IAM roles to end-user applications. Since we'll be integrating our Cognito deployment and users with other AWS services, we'll go ahead and create this identity pool now.
131
139
132
140
#### High-Level Instructions
133
141
@@ -142,7 +150,9 @@ You will need to create a Cognito Identity Pool linked to the Cognito User Pool
142
150
143
151
1. Input `wildrydes_identity_pool` as the Identity pool name.
144
152
145
-
1. Under Authentication providers, within the Cognito tab, input the User Pool ID and App client Id you copied previously to the scratchpad tab.
153
+
1. Expand Authentication providers.
154
+
155
+
1. Within the Cognito tab, input the User Pool ID and App client Id you copied previously to the scratchpad tab.
146
156
147
157

148
158
@@ -162,12 +172,14 @@ Now that you've created and configured your Cognito User Pool and Identity Pool,
162
172
163
173
#### High-Level Instructions
164
174
165
-
You will import the AWS Amplify library into the project then add sign-up and sign-in utility classes to integrate with our existing UI and front-end components.
175
+
You will import the [AWS Amplify](https://aws-amplify.github.io/) JavaScript library into the project then add sign-up and sign-in utility classes to integrate with our existing UI and front-end components.
176
+
177
+
You'll need to complete the implementation of the onSubmitForm and onSubmitVerification methods within the /Auth/website/src/auth/signIn.js file, as well as the methods of the same name within the /Auth/website/src/auth/signIn.js file. Finally, you'll need to complete the implementation of a method to check whether the user is authenticated within the /Auth/website/src/index.js page.
166
178
167
179
<details>
168
180
<summary><strong>Step-by-step instructions (expand for details)</strong></summary><p>
169
181
170
-
1. Before using any AWS Amplify modules, we first need to configure Amplify to use our newly created Cognito resources by updating `/website/src/amplify-config.js`.
182
+
1. Before using any AWS Amplify modules, we first need to configure Amplify to use our newly created Cognito resources by updating `/Auth/website/src/amplify-config.js`.
171
183
172
184
1. After opening this file in your Cloud9 IDE editor, find an replace the following parameters with values from your previous scratchpad:
173
185
- `identityPoolId`
@@ -191,8 +203,10 @@ You will import the AWS Amplify library into the project then add sign-up and si
1. **Save your changes** to the `/website/src/index.js` file.
194
208
195
-
1. Now that we've imported the Amplify and configured the Amplify library, we need to update our application's code to sign-up users using Amplify and Cognito User Pools by finding and replacing the following methods within the `/website/src/auth/SignUp.js` file with the code below then save your changes.
209
+
1. Now that we've imported the Amplify and configured the Amplify library, we need to update our application's code to sign-up users using Amplify and Cognito User Pools by finding and replacing the following methods within the `/website/src/auth/SignUp.js` file with the code below **then save your changes**.
196
210
197
211
```
198
212
async onSubmitForm(e) {
@@ -240,7 +254,7 @@ You will import the AWS Amplify library into the project then add sign-up and si
240
254
}
241
255
```
242
256
243
-
1. You additionally need to integrate the sign-in capability to use AWS Amplify and Cognito by finding and replacing the following methods within the `/website/src/auth/SignIn.js` file with the code below then save your changes.
257
+
1. You additionally need to integrate the sign-in capability to use AWS Amplify and Cognito by finding and replacing the following methods within the `/website/src/auth/SignIn.js` file with the code below **then save your changes**.
244
258
245
259
```
246
260
async onSubmitForm(e) {
@@ -275,7 +289,7 @@ You will import the AWS Amplify library into the project then add sign-up and si
275
289
const data = await Auth.confirmSignIn(
276
290
this.state.userObject,
277
291
this.state.code
278
-
);
292
+
);
279
293
console.log('Cognito User Data:', data);
280
294
const session = await Auth.currentSession();
281
295
// console.log('Cognito User Access Token:', session.getAccessToken().getJwtToken());
@@ -300,7 +314,9 @@ Now that you have integrated our Amplify code into our application, you need to
300
314
301
315
Return to your browser tab where you started your Wild Rydes application earlier after popping out from the Cloud9 IDE once in preview mode. This page automatically refreshes after you save any code changes so should now reflect all of your changes and be ready for testing.
302
316
303
-
Sign-up as a new user then sign-in with that user. Provide a valid phone number with `+country_code` first preceeding the number. For a US-based phone number, an example would be `+14251234567`. You should then see that a verification message is sent with a one-time code upon registering, which is required before you're able to sign-in.
317
+
Visit the /register path to sign-up as a new user, providing a valid phone number with `+country_code` first preceeding the number. For a US-based phone number, an example would be `+14251234567`. You should then see that a verification message is sent with a one-time code upon registering, which is required before you're able to sign-in.
318
+
319
+
After signing up as a new user, sign-in with the same user. If the page loads a map, sign-in was successful and you have successfully integrated Cognito for app authentication.
304
320
305
321
<details>
306
322
<summary><strong>Step-by-step instructions (expand for details)</strong></summary><p>
@@ -313,11 +329,15 @@ Sign-up as a new user then sign-in with that user. Provide a valid phone number
313
329
314
330
1. On the verify e-mail screen, enter the one-time code sent to your e-mail address provided then choose **Verify**.
315
331
332
+
**Note**: Be sure to check your spam folder for the e-mail with your verification code if you do not see it in your inbox.
333
+
316
334
1. Assuming no errors were encountered, you will be redirected to the Sign-in screen. Now, re-enter the same e-mail address and password you chose at registration.
317
335
318
336
1. **If prompted for an MFA code**, check your phone entered previously for an SMS message. Enter your **SMS MFA code** at the verification code prompt then choose **Verify**. If not prompted for an MFA code, skip this step.
319
337
320
-
1. If the page then loads a map, sign-in was successful and you have successfully integrated Cognito for app authentication.
338
+
1. If the page then loads a map, sign-in was successful and you have successfully integrated Cognito for app authentication.
339
+
340
+
1. Optionally, you may scroll down beyond the map to copy your user's identity token and decode it by pasting it into the 'encoded' input box at [JWT.io](http://jwt.io). You will see all of your user's attributes are encoded within the token, along with other standard attributes such as the time the token was issued, the time the token expires, the user's unique ID, and more.
0 commit comments