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

Commit efbafd0

Browse files
committed
Refined module 2 instructions
1 parent c07b6e9 commit efbafd0

File tree

5 files changed

+24
-14
lines changed

5 files changed

+24
-14
lines changed

Auth/2_ServerlessAPI/Optional-APIGateway-IAMAuth.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
# Optional Module 2 Extension: Serverless APIs with IAM-based Authorization
22

3-
In this **optional extension to module 2**, you will update your serverless backend for your Wild Rydes application leveraging [Amazon API Gateway](https://aws.amazon.com/api-gateway/) and [AWS Lambda](https://aws.amazon.com/lambda/) to use IAM-based authorization as a more secure authentication option which includes request signing.
3+
In this **optional extension to module 2**, you will update your serverless backend for your Wild Rydes application leveraging [Amazon API Gateway](https://aws.amazon.com/api-gateway/) and [AWS Lambda](https://aws.amazon.com/lambda/) to use request signing with IAM-based authorization as a more secure authentication option.
44

5-
**If you would like to skip this optional extension**, you are able to proceed to module 3, [IAM-based Authorization](../3_IAMAuthorization).
5+
**If you would like to skip this optional extension**, you are able to proceed to module 3 directly, [IAM-based Authorization](../3_IAMAuthorization).
66

77
## Solution Architecture
88

99
Building on Module 2, this module updates our Serverless backend built earlier using Amazon API Gateway and AWS Lambda to use IAM-based authorization. This extends our authorization capability to offer fine-grained access control authorizing differently per API operation and enhancing security via request signing. By enabling IAM-based authorization, you will use the same type of authentication, authorization, and request signing used by all AWS services and SDKs.
1010

1111
[Request signing](https://docs.aws.amazon.com/general/latest/gr/signing_aws_api_requests.html) is a more secure implementation of API request authentication where each API request made is signed with a signature unique to the request itself. Hence, no static API keys or bearer tokens are directly sent to the backend service and any man-in-the-middle attacks would not be able to use such API keys or bearer tokens to impersonate a valid user with the backend resources. AWS APIs and SDKs use a request signing algorithm nammed [Signature V4 (Sigv4)](https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html) which is what you will enable your API to use in this module.
1212

13+
> For production APIs, you should use either the token-based authorization OR request signing authorization via IAM demonstrated in this module, but not use both for the same API.
14+
1315
![Module 2 architecture](../images/wildrydes-module2-architecture.png)
1416

1517
## Implementation Overview
@@ -42,15 +44,19 @@ In the IAM console, assocate the *WildRydesAPI-StandardUserPolicy* with your Cog
4244
1. Review the policy which was created by CloudFormation to authorize requests to your API Gateway deployment.
4345

4446
![WildRydesAPI Policy Details](../images/iam-wildrydesapi-policy-details.png)
45-
> This policy allows access to invoke any method within the /rides path on any stage of API Gatweay. For more details about authoring IAM policies for API Gateway, visit the [controlling access to an API with IAM permissions](https://docs.aws.amazon.com/apigateway/latest/developerguide/permissions.html) documentation.
47+
> This policy allows access to invoke any method on the /ride path for any API stage of your API gateway backend. For more details about authoring IAM policies for API Gateway, visit the [controlling access to an API with IAM permissions](https://docs.aws.amazon.com/apigateway/latest/developerguide/permissions.html) documentation.
4648

4749
1. Choose **Roles**.
4850

4951
1. Search for *WildRydes* to find the two roles which were created by Cognito Identity Pools when you created the Identity Pool in module one. Should you not be able to find the roles here, you can alternatively go to the **Cognito Federated Identities** console, find the correct identity pool, then click **Edit Identity Pool** in the top-right corner to see the roles listed. Each identity pool has both an Unauthenticated user role and an Authenticated user role.
5052

51-
1. Once you have found the names of the roles, go back to the IAM console and select the *Auth* role for your authenticated users.
53+
1. Once you have found the names of the roles, go back to the IAM console and **select the *Auth* role** for your authenticated users.
54+
55+
> If the full name of the role is hidden from view due to column width, you can hover over the partially visible name of the role to see the full name of the role as a tool tip.
56+
57+
![IAM WildRydes Auth Role Selction](../images/iam-wildrydes-role-selection.png)
5258

53-
1. Choose **Attach policies** to attach
59+
1. Choose **Attach policies**.
5460

5561
1. Search for `WildRydes` and check the box next to the policy named *WildRydesAPI-StandardUserAccess*.
5662

@@ -134,7 +140,7 @@ Now that you've deployed the new authorizer configuration to production, all API
134140
'Content-Type': 'application/json'
135141
}
136142
};
137-
logger.info('API Request:', apiRequest);
143+
console.log('API Request:', apiRequest);
138144
return await API.post(apiName, apiPath, apiRequest);
139145
}
140146
```
@@ -143,7 +149,11 @@ Now that you've deployed the new authorizer configuration to production, all API
143149
144150
18. 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 message which includes the API Request details, including the full signature and headers of the request.
145151
152+
> This message starts with POST /prod/ride then shows the headers of the request made.
153+
154+
> You may notice that there were both x-amz-date and x-amz-security-token headers sent among other headers. These two headers are part of the overall request signature, along with the Authorization header.
155+
146156
</p></details>
147157
<br>
148158
149-
If the API now invokes correctly and application funcions as expected again, you can move on to the next module, [IAM-based Authorization](../3_IAMAuthorization).
159+
If your API now invokes correctly and application funcions as expected summoning unicorns again, you can proceed to the next module, [IAM-based Authorization](../3_IAMAuthorization).

Auth/2_ServerlessAPI/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ First, expand your *amplify-config.js* file to store your new API Gateway endpoi
6767
endpoints: [
6868
{
6969
name: 'WildRydesAPI',
70-
endpoint: 'https://1ngrgqjt6c.execute-api.us-east-1.amazonaws.com/prod'
70+
endpoint: 'https://1ngrgqjt6c.execute-api.us-east-1.amazonaws.com/prod',
71+
region: 'us-east-1'
7172
}
7273
]
7374
},
@@ -86,7 +87,6 @@ First, expand your *amplify-config.js* file to store your new API Gateway endpoi
8687

8788
```
8889
async getData(pin) {
89-
Amplify.Logger.LOG_LEVEL = 'DEBUG';
9090
const apiRequest = {
9191
body: {
9292
PickupLocation: {
@@ -99,7 +99,7 @@ First, expand your *amplify-config.js* file to store your new API Gateway endpoi
9999
'Content-Type': 'application/json'
100100
}
101101
};
102-
logger.info('API Request:', apiRequest);
102+
console.log('API Request:', apiRequest);
103103
return await API.post(apiName, apiPath, apiRequest);
104104
}
105105
```
@@ -234,19 +234,19 @@ Now that you've deployed the new authorizer configuration to production, all API
234234
'Content-Type': 'application/json'
235235
}
236236
};
237-
logger.info('API Request:', apiRequest);
237+
console.log('API Request:', apiRequest);
238238
return await API.post(apiName, apiPath, apiRequest);
239239
}
240240
```
241241
242242
35. Allow the application to refresh, sign-in again, and request a ride.
243243
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 INFO message which includes the API Request details once expanded, including the full headers and body of the request.
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.
245245
246246
</p></details>
247247
<br>
248248
249-
If the API now invokes correctly and application funcions as expected again, you may **proceed to complete either**:
249+
If the API now invokes correctly and application funcions as expected summoning unicorns, you may **proceed to complete either**:
250250
251251
- **Optional module extension** with [Fine-grained IAM-based authorization with API Gateway](./Optional-APIGateway-IAMAuth.md)
252252
134 KB
Loading
17 KB
Loading

Auth/website/src/pages/MainApp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class MainApp extends React.Component {
6060
* @param {Number} longitude
6161
*/
6262
async getData(pin) {
63-
throw new Error('Request a Ride is not implemented');
63+
console.error('Request a Ride is not implemented');
6464
}
6565

6666
/**

0 commit comments

Comments
 (0)