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
* Use @tsconfig/node14
* Pass cookiesettings to React App. Support host-only cookie in React App
* In static site mode, default to sending the refresh token cookie ONLY when navigating to the refresh endpoint
* Tweak and document cookie settings in React App
* Refactored the code for better readability, and use host-only cookies
* v2.1.0
* Tweak docs
* Further simplfy error scenario's
* Fixed spelling
Copy file name to clipboardexpand all lines: README.md
+6-5
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
This repo accompanies the [blog post](https://aws.amazon.com/blogs/networking-and-content-delivery/authorizationedge-using-cookies-protect-your-amazon-cloudfront-content-from-being-downloaded-by-unauthenticated-users/).
4
4
5
-
In that blog post a solution is explained, that puts **Cognito** authentication in front of (S3) downloads from **CloudFront**, using **Lambda@Edge**. **JWT's** are transferred using **cookies** to make authorization transparent to clients.
5
+
In that blog post a solution is explained, that puts **Cognito** authentication in front of (S3) downloads from **CloudFront**, using **Lambda@Edge**. **JWTs** are transferred using **cookies** to make authorization transparent to clients.
6
6
7
7
The sources in this repo implement that solution.
8
8
@@ -22,7 +22,7 @@ More deployment options below: [Deploying the solution](#deploying-the-solution)
22
22
23
23
### Alternative: use HTTP headers
24
24
25
-
This repo is the "sibling" of another repo here on aws-samples ([authorization-lambda-at-edge](https://github.com/aws-samples/authorization-lambda-at-edge)). The difference is that the solution in that repo uses http headers (not cookies) to transfer JWT's. While also a valid approach, the downside of it is that your Web App (SPA) needs to be altered to pass these headers, as browsers do not send these along automatically (which they do for cookies).
25
+
This repo is the "sibling" of another repo here on aws-samples ([authorization-lambda-at-edge](https://github.com/aws-samples/authorization-lambda-at-edge)). The difference is that the solution in that repo uses http headers (not cookies) to transfer JWTs. While also a valid approach, the downside of it is that your Web App (SPA) needs to be altered to pass these headers, as browsers do not send these along automatically (which they do for cookies).
26
26
27
27
### Alternative: build an Auth@Edge solution yourself, using NPM library [cognito-at-edge](https://github.com/awslabs/cognito-at-edge)
28
28
@@ -36,7 +36,7 @@ This repo contains (a.o.) the following files and directories:
36
36
37
37
Lambda@Edge functions in [src/lambda-edge](src/lambda-edge):
38
38
39
-
-[check-auth](src/lambda-edge/check-auth): Lambda@Edge function that checks each incoming request for valid JWT's in the request cookies
39
+
-[check-auth](src/lambda-edge/check-auth): Lambda@Edge function that checks each incoming request for valid JWTs in the request cookies
40
40
-[parse-auth](src/lambda-edge/parse-auth): Lambda@Edge function that handles the redirect from the Cognito hosted UI, after the user signed in
41
41
-[refresh-auth](src/lambda-edge/refresh-auth): Lambda@Edge function that handles JWT refresh requests
42
42
-[sign-out](src/lambda-edge/sign-out): Lambda@Edge function that handles sign-out
@@ -46,7 +46,7 @@ Lambda@Edge functions in [src/lambda-edge](src/lambda-edge):
46
46
CloudFormation custom resources in [src/cfn-custom-resources](src/cfn-custom-resources):
47
47
48
48
-[us-east-1-lambda-stack](src/cfn-custom-resources/us-east-1-lambda-stack): Lambda function that implements a CloudFormation custom resource that makes sure the Lambda@Edge functions are deployed to us-east-1 (which is a CloudFront requirement, see below.)
49
-
-[react-app](src/cfn-custom-resources/react-app): A sample React app that is protected by the solution. It uses AWS Amplify Framework to read the JWT's from cookies. The directory also contains a Lambda function that implements a CloudFormation custom resource to build the React app and upload it to S3
49
+
-[react-app](src/cfn-custom-resources/react-app): A sample React app that is protected by the solution. It uses AWS Amplify Framework to read the JWTs from cookies. The directory also contains a Lambda function that implements a CloudFormation custom resource to build the React app and upload it to S3
50
50
-[static-site](src/cfn-custom-resources/static-site): A sample static site (see [SPA mode or Static Site mode?](#spa-mode-or-static-site-mode)) that is protected by the solution. The directory also contains a Lambda function that implements a CloudFormation custom resource to upload the static site to S3
51
51
-[user-pool-client](src/cfn-custom-resources/user-pool-client): Lambda function that implements a CloudFormation custom resource to update the User Pool client with OAuth config
52
52
-[user-pool-domain](src/cfn-custom-resources/user-pool-domain): Lambda function that implements a CloudFormation custom resource to lookup the User Pool's domain, at which the Hosted UI is available
@@ -156,7 +156,7 @@ You can deploy this solution to any AWS region of your liking (that supports the
156
156
The default deployment mode of this sample application is "SPA mode" - which entails some settings that make the deployment suitable for hosting a SPA such as a React/Angular/Vue app:
157
157
158
158
- The User Pool client does not use a client secret, as that would not make sense for JavaScript running in the browser
159
-
- The cookies with JWT's are not "http only", so that they can be read and used by the SPA (e.g. to display the user name, or to refresh tokens)
159
+
- The cookies with JWTs are not "http only", so that they can be read and used by the SPA (e.g. to display the user name, or to refresh tokens)
160
160
- 404's (page not found on S3) will return index.html, to enable SPA-routing
161
161
162
162
If you do not want to deploy a SPA but rather a static site, then it is more secure to use a client secret and http-only cookies. Also, SPA routing is not needed then. To this end, upon deploying, set parameter `EnableSPAMode` to false (`--parameter-overrides EnableSPAMode="false"`). This will:
@@ -165,6 +165,7 @@ If you do not want to deploy a SPA but rather a static site, then it is more sec
165
165
- Set cookies to be http only by default (unless you've provided other cookie settings explicitly)
166
166
- Skip deployment of the sample React app. Rather a sample index.html is uploaded, that you can replace with your own pages
167
167
- Skip setting up the custom error document mapping 404's to index.html (404's will instead show the plain S3 404 page)
168
+
- Set the refresh token's path explicitly to the refresh path, `"/refreshauth"` instead of `"/"` (unless you've provided other cookie settings explicitly), and thus the refresh token will not be sent to other paths (more secure and more performant)
168
169
169
170
In case you're choosing Static Site mode, it might make sense to set parameter `RewritePathWithTrailingSlashToIndex` to `true` (`--parameter-overrides RewritePathWithTrailingSlashToIndex="true"`). This will append `index.html` to all paths that include a trailing slash, so that e.g. when the user goes to `/some/sub/dir/`, this is translated to `/some/sub/dir/index.html` in the request to S3.
Copy file name to clipboardexpand all lines: SERVERLESS-REPO.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
This serverless application accompanies the [blog post](https://aws.amazon.com/blogs/networking-and-content-delivery/authorizationedge-using-cookies-protect-your-amazon-cloudfront-content-from-being-downloaded-by-unauthenticated-users/).
4
4
5
-
In that blog post a solution is explained, that puts Cognito authentication in front of (S3) downloads from CloudFront, using Lambda@Edge. JWT's are transferred using cookies to make authorization transparent to clients.
5
+
In that blog post a solution is explained, that puts Cognito authentication in front of (S3) downloads from CloudFront, using Lambda@Edge. JWTs are transferred using cookies to make authorization transparent to clients.
6
6
7
7
This application is an implementation of that solution. If you deploy it, this is what you get:
0 commit comments