@liflig/cdk-cloudfront-auth 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +63 -0
- package/dist/check-auth/index.js +2 -0
- package/dist/check-auth/index.js.LICENSE.txt +17 -0
- package/dist/generate-secret/index.js +1 -0
- package/dist/http-headers/index.js +2 -0
- package/dist/http-headers/index.js.LICENSE.txt +6 -0
- package/dist/parse-auth/index.js +2 -0
- package/dist/parse-auth/index.js.LICENSE.txt +31 -0
- package/dist/refresh-auth/index.js +2 -0
- package/dist/refresh-auth/index.js.LICENSE.txt +31 -0
- package/dist/sign-out/index.js +2 -0
- package/dist/sign-out/index.js.LICENSE.txt +17 -0
- package/lib/client-secret.d.ts +10 -0
- package/lib/client-secret.js +54 -0
- package/lib/client-update.d.ts +14 -0
- package/lib/client-update.js +59 -0
- package/lib/cloudfront-auth.d.ts +132 -0
- package/lib/cloudfront-auth.js +267 -0
- package/lib/generate-secret.d.ts +15 -0
- package/lib/generate-secret.js +71 -0
- package/lib/handlers/check-auth.d.ts +7 -0
- package/lib/handlers/generate-secret.d.ts +9 -0
- package/lib/handlers/http-headers.d.ts +1 -0
- package/lib/handlers/parse-auth.d.ts +1 -0
- package/lib/handlers/refresh-auth.d.ts +1 -0
- package/lib/handlers/sign-out.d.ts +1 -0
- package/lib/handlers/util/axios.d.ts +4 -0
- package/lib/handlers/util/axios.js +42 -0
- package/lib/handlers/util/base64.d.ts +8 -0
- package/lib/handlers/util/base64.js +26 -0
- package/lib/handlers/util/cloudfront.d.ts +17 -0
- package/lib/handlers/util/cloudfront.js +102 -0
- package/lib/handlers/util/config.d.ts +26 -0
- package/lib/handlers/util/config.js +48 -0
- package/lib/handlers/util/cookies.d.ts +29 -0
- package/lib/handlers/util/cookies.js +115 -0
- package/lib/handlers/util/jwt.d.ts +17 -0
- package/lib/handlers/util/jwt.js +59 -0
- package/lib/handlers/util/logger.d.ts +16 -0
- package/lib/handlers/util/logger.js +55 -0
- package/lib/handlers/util/nonce.d.ts +9 -0
- package/lib/handlers/util/nonce.js +47 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +19 -0
- package/lib/lambdas.d.ts +33 -0
- package/lib/lambdas.js +88 -0
- package/package.json +75 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Henrik Steen
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# CloudFront authorization with Cognito for CDK
|
|
2
|
+
|
|
3
|
+
Easily add Cognito-based authorization to your CloudFront distribution,
|
|
4
|
+
to place static files behind authorization.
|
|
5
|
+
|
|
6
|
+
This is based on https://github.com/aws-samples/cloudfront-authorization-at-edge.
|
|
7
|
+
|
|
8
|
+
## Usage
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @liflig/cdk-cloudfront-auth
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Deploy the Lambda@Edge functions to us-east-1:
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
// In a stack deployed to us-east-1.
|
|
18
|
+
const authLambdas = new AuthLambdas(this, "AuthLambdas", {
|
|
19
|
+
regions: ["eu-west-1"], // Regions to make Lambda version params available.
|
|
20
|
+
})
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Deploy the Cognito and CloudFront setup in whatever region
|
|
24
|
+
of your choice:
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
const auth = new CloudFrontAuth(this, "Auth", {
|
|
28
|
+
cognitoAuthDomain: `${domain.domainName}.auth.${region}.amazoncognito.com`,
|
|
29
|
+
authLambdas, // AuthLambdas from above
|
|
30
|
+
userPool, // Cognito User Pool
|
|
31
|
+
})
|
|
32
|
+
const distribution = new cloudfront.Distribution(this, "Distribution", {
|
|
33
|
+
defaultBehavior: auth.createProtectedBehavior(origin),
|
|
34
|
+
additionalBehaviors: auth.createAuthPagesBehaviors(origin),
|
|
35
|
+
})
|
|
36
|
+
auth.updateClient("ClientUpdate", {
|
|
37
|
+
signOutUrl: `https://${distribution.distributionDomainName}${auth.signOutRedirectTo}`,
|
|
38
|
+
callbackUrl: `https://${distribution.distributionDomainName}${auth.callbackPath}`,
|
|
39
|
+
})
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
If using `CloudFrontWebDistribution` instead of `Distribution`:
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
const distribution = new cloudfront.CloudFrontWebDistribution(this, "Distribution", {
|
|
46
|
+
originConfigs: [
|
|
47
|
+
{
|
|
48
|
+
behaviors: [
|
|
49
|
+
...auth.authPages,
|
|
50
|
+
{
|
|
51
|
+
isDefaultBehavior: true,
|
|
52
|
+
lambdaFunctionAssociations: auth.authFilters,
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
})
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Customizing authorization
|
|
61
|
+
|
|
62
|
+
The `CloudFrontAuth` construct accepts a `requireGroupAnyOf` property
|
|
63
|
+
that causes access to be restricted to only users in specific groups.
|