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/2_ServerlessAPI/README.md
+15-9Lines changed: 15 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,6 +22,8 @@ You will be creating your Serverless API built with Amazon API Gateway, AWS Lamb
22
22
23
23
Create a new WildRydes Serverless Backend stack by launching a CloudFormation stack based on the **ServerlessBackend.yaml** file in the module 2 folder. Name the stack `WildRydesBackend`.
24
24
25
+
This WildRydes backend CloudFormation template will provision your API Gateway deployment with Lambda functions for compute, a DynamoDB database for persistence, and an S3 bucket for photo uploads which will be used in module 3. Additionally, the necessary function invocation permissions and execution role for the Lambda function will also be provisioned.
26
+
25
27
Region Name | Region Code | Launch
26
28
------|-----|-----
27
29
US East (N. Virginia) | us-east-1 | [](https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?stackName=WildRydesBackend&templateURL=https://s3.amazonaws.com/wildrydes-us-east-1/Auth/2_ServerlessAPI/ServerlessBackend.yaml)
@@ -121,13 +123,15 @@ You should be informed of your unicorn's arrival momentarily.
121
123
#### Background
122
124
Amazon API Gateway can use the JSON Web tokens (JWT) returned by Cognito User Pools to authenticate API calls. In this step, you'll configure an authorizer for your API to use the user pool you created in [module 1](../1_UserAuthentication).
123
125
126
+
Since Cognito User Pools implements [OpenID Connect](https://en.wikipedia.org/wiki/OpenID_Connect) JSON web tokens, API Gateway is able to compare the signature of an access or identity token against the known public keys of the Cognito User Pool which allows verification and authentication to happen without having to write additional code in your application.
127
+
124
128
#### High-Level Instructions
125
-
In the Amazon API Gateway console, create a new Cognito user pool authorizer for your API. Configure it to use the user pool that you created in the previous module. You can test the configuration in the console by copying and pasting the identity token presented to you after you log in via the `/signin` path of your current website. Once setup, you will change your application's code to send the proper JSON web token with its API requests to authenticate.
129
+
In the Amazon API Gateway console, create a new Cognito user pool authorizer for your API. Configure it to use the user pool that you created in the previous module. You can test the configuration in the console by copying and pasting the identity token printed to the console after you log in via the `/signin` path of your current website. Once setup, you will change your application's code to send the proper JSON web token with its API requests to authenticate.
126
130
127
131
<details>
128
132
<summary><strong>Step-by-step instructions (expand for details)</strong></summary><p>
129
133
130
-
1. In the AWS Management Console choose **Services** then select **API Gateway** under Security, Identity, and Compliance.
134
+
1. In the AWS Management Console choose **Services** then select **API Gateway** under Networking and Content Delivery.
131
135
132
136
2. Choose the API named *WildRydes*.
133
137
@@ -208,17 +212,17 @@ In the Amazon API Gateway console, create a new Cognito user pool authorizer for
208
212
209
213
Now that you've deployed the new authorizer configuration to production, all API requests must be authenticated to be processed.
210
214
211
-
30. Return to your Wild Rydes app, sign in at */signin* if necessary, and attempt to request a ride.
215
+
29. Return to your Wild Rydes app, sign in at */signin* if necessary, and attempt to request a ride.
212
216
213
-
31. You should receive an *Error finding unicorn*. If you open the developer console, you will see that we received a HTTP 401 error, which means it was an unauthorized request. To authenticate our requests properly, we need to send an Authorization header.
217
+
30. You should receive an *Error finding unicorn*. If you open the developer console, you will see that we received a HTTP 401 error, which means it was an unauthorized request. To authenticate our requests properly, we need to send an Authorization header.
214
218
215
219
> If you at first still that you requests go through without any errors, try requesting a ride again in 30-60 seconds to allow the API Gateway changes to fully propagate.
216
220
217
-
32. Go back to Cloud9 and open the */website/src/pages/MainApp.js* files.
221
+
31. Go back to Cloud9 and open the */website/src/pages/MainApp.js* files.
218
222
219
-
33. Browse down to the *getData* method you previously updated. You will notice that the headers for the request currently include a blank *Authorization* header.
223
+
32. Browse down to the *getData* method you previously updated. You will notice that the headers for the request currently include a blank *Authorization* header.
220
224
221
-
34. Replace your current *getData* method with the following code which sends your user's Cognito identity token, encoded as a JSON web token, in the *Authorization* header with every request.
225
+
33. Replace your current *getData* method with the following code which sends your user's Cognito identity token, encoded as a JSON web token, in the *Authorization* header with every request.
222
226
223
227
```
224
228
async getData(pin) {
@@ -239,9 +243,11 @@ Now that you've deployed the new authorizer configuration to production, all API
239
243
}
240
244
```
241
245
242
-
35. Allow the application to refresh, sign-in again, and request a ride.
246
+
34. Allow the application to refresh, sign-in again, and request a ride.
247
+
248
+
35. The unicorn ride request should be fulfilled as before now. To see the full request headers which were sent, look at the developer console for an *API Request* informational message which includes the API Request details once expanded, including the full headers and body of the request.
243
249
244
-
36. The unicorn ride request should be fulfilled as before now. To see the full request headers which were sent, look at the developer console for an *API Request* informational message which includes the API Request details once expanded, including the full headers and body of the request.
Copy file name to clipboardExpand all lines: Auth/3_IAMAuthorization/README.md
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ If you're using the latest version of the Chrome, Firefox, or Safari web browser
16
16
17
17
### 1. Setup S3 bucket for use with AWS Amplify
18
18
19
-
You will need for your S3 bucket to be properly associated with Amplify for seamless upload and data of data. To save time, the Serverless Backend CloudFormation template that created the serverless backend for this workshop also created an S3 bucket for this purpose with the cross-origin resource sharing (CORS) settings already set. You just need to associate this bucket with your application's code.
19
+
You will need to configure AWS Amplify to securely store profile images in an S3 bucket. To save time, the Serverless Backend CloudFormation template that created the serverless backend API for this workshop also created an S3 bucket for this purpose with the cross-origin resource sharing (CORS) settings already set. You just need to associate this bucket with your application's code.
20
20
21
21
#### High-Level Instructions
22
22
@@ -82,6 +82,8 @@ Browse to the IAM console and find your Cognito Identity Pool's authenticated us
82
82
1. Paste the following IAM policy statements for S3 access. After pasting, you will need to go **replace the bucket name** listed in all caps with your bucket name (a total of 4 times).
83
83
84
84
> Be sure to leave the parts of the resource names before and after the replacement value alone and not accidentally modify them.
85
+
86
+
> The following policy makes use of IAM policy variables where *${aws:userid}* represents the current authenticated user's unique Cognito identity ID. This policy's effective permissions will allow all authenticated users to read objects from the root of the bucket and any /protected path, but only allow users to read their own private sub-path and write to their sub-path within the protected path. These are default paths that are integrated with AWS Amplify to easily set [file access levels](https://aws-amplify.github.io/docs/js/storage#file-access-levels).
85
87
86
88
```
87
89
{
@@ -162,7 +164,7 @@ Authenticate in the Wild Rydes app if you're not already logged in, then browse
162
164
163
165
### 4. Store profile picture links in Cognito User Pools profile
164
166
165
-
With our image uploads now working, all will work as expected until you close your browser, but at that point the reference between your user profile and your profile picture will be lost. To fix this, you will leverage a Cognito User Pools user attribute called *picture* to persist the S3 object key so the same image can be loaded upon each login and persisted to be shown to the unicorns when you request a ride.
167
+
With our image uploads now working, all will work as expected until you close your browser, but at that point the reference between your user profile and your profile picture will be lost. To fix this, you will leverage a Cognito User Pools user attribute called *picture* to persist the S3 object key so the same image can be loaded upon each login and persisted to be shown to the unicorns when you request a ride. You will need to update */website/src/pages/Profile.js* and a method called *onImageLoad* to make this possible.
0 commit comments