-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix/push-notification-flush-events
- Loading branch information
Showing
124 changed files
with
6,345 additions
and
3,577 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# amplify | ||
node_modules | ||
.amplify | ||
amplify_outputs* | ||
amplifyconfiguration* |
14 changes: 14 additions & 0 deletions
14
infra-gen2/backends/auth/email-sign-in/amplify/auth/resource.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { defineAuth } from "@aws-amplify/backend"; | ||
|
||
/** | ||
* Define and configure your auth resource | ||
* @see https://docs.amplify.aws/gen2/build-a-backend/auth | ||
*/ | ||
export const auth = defineAuth({ | ||
loginWith: { | ||
email: true, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { defineBackend } from "@aws-amplify/backend"; | ||
import { addAuthUserExtensions } from "infra-common"; | ||
import { auth } from "./auth/resource"; | ||
|
||
const backend = defineBackend({ | ||
auth, | ||
}); | ||
|
||
const resources = backend.auth.resources; | ||
const { userPool, cfnResources } = resources; | ||
const { stack } = userPool; | ||
const { cfnUserPool } = cfnResources; | ||
|
||
// Adds infra for creating/deleting users via App Sync and fetching confirmation | ||
// and MFA codes from App Sync. | ||
const customOutputs = addAuthUserExtensions({ | ||
name: "email-sign-in", | ||
stack, | ||
userPool, | ||
cfnUserPool, | ||
}); | ||
backend.addOutput(customOutputs); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "module" | ||
} |
17 changes: 17 additions & 0 deletions
17
infra-gen2/backends/auth/email-sign-in/amplify/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2022", | ||
"module": "es2022", | ||
"moduleResolution": "bundler", | ||
"resolveJsonModule": true, | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"paths": { | ||
"$amplify/*": [ | ||
"../.amplify/generated/*" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "email-sign-in", | ||
"version": "1.0.0", | ||
"main": "index.js" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# amplify | ||
node_modules | ||
.amplify | ||
amplify_outputs* | ||
amplifyconfiguration* |
14 changes: 14 additions & 0 deletions
14
infra-gen2/backends/auth/phone-sign-in/amplify/auth/resource.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { defineAuth } from "@aws-amplify/backend"; | ||
|
||
/** | ||
* Define and configure your auth resource | ||
* @see https://docs.amplify.aws/gen2/build-a-backend/auth | ||
*/ | ||
export const auth = defineAuth({ | ||
loginWith: { | ||
phone: true, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { defineBackend } from "@aws-amplify/backend"; | ||
import { addAuthUserExtensions } from "infra-common"; | ||
import { auth } from "./auth/resource"; | ||
|
||
const backend = defineBackend({ | ||
auth, | ||
}); | ||
|
||
const resources = backend.auth.resources; | ||
const { userPool, cfnResources } = resources; | ||
const { stack } = userPool; | ||
const { cfnUserPool } = cfnResources; | ||
|
||
// Adds infra for creating/deleting users via App Sync and fetching confirmation | ||
// and MFA codes from App Sync. | ||
const customOutputs = addAuthUserExtensions({ | ||
name: "phone-sign-in", | ||
stack, | ||
userPool, | ||
cfnUserPool, | ||
}); | ||
backend.addOutput(customOutputs); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "module" | ||
} |
17 changes: 17 additions & 0 deletions
17
infra-gen2/backends/auth/phone-sign-in/amplify/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2022", | ||
"module": "es2022", | ||
"moduleResolution": "bundler", | ||
"resolveJsonModule": true, | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"paths": { | ||
"$amplify/*": [ | ||
"../.amplify/generated/*" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "phone-sign-in", | ||
"version": "1.0.0", | ||
"main": "index.js" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# auth-user-extensions | ||
|
||
This directory contains extensions useful for managing authorized users, including: | ||
|
||
- creating & deleting users via App Sync | ||
- sending confirmation codes to App Sync instead of email/SMS |
35 changes: 35 additions & 0 deletions
35
infra-gen2/infra-common/src/auth-user-extensions/auth-user-extensions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { BackendBase } from "@aws-amplify/backend"; | ||
import { Stack } from "aws-cdk-lib"; | ||
import { CfnUserPool, IUserPool } from "aws-cdk-lib/aws-cognito"; | ||
import { addCreateUserLambda } from "./create-user-lambda"; | ||
import { addCustomSenderLambda } from "./custom-sender-lambda"; | ||
import { addDeleteUserLambda } from "./delete-user-lambda"; | ||
import { addUserGraphql } from "./user-graphql"; | ||
|
||
type AmplifyOutputs = Parameters<BackendBase["addOutput"]>[0]; | ||
|
||
export const addAuthUserExtensions = ({ | ||
name, | ||
stack, | ||
userPool, | ||
cfnUserPool, | ||
}: { | ||
name: string; | ||
stack: Stack; | ||
userPool: IUserPool; | ||
cfnUserPool: CfnUserPool; | ||
}): AmplifyOutputs => { | ||
const graphQL = addUserGraphql(stack); | ||
addCustomSenderLambda({ name, stack, cfnUserPool, graphQL }); | ||
addCreateUserLambda({ name, stack, userPool, graphQL }); | ||
addDeleteUserLambda({ name, stack, userPool, graphQL }); | ||
return { | ||
data: { | ||
aws_region: stack.region, | ||
url: graphQL.graphqlUrl, | ||
api_key: graphQL.apiKey, | ||
default_authorization_type: "API_KEY", | ||
authorization_types: [], | ||
}, | ||
}; | ||
}; |
46 changes: 46 additions & 0 deletions
46
infra-gen2/infra-common/src/auth-user-extensions/create-user-lambda.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { Stack } from "aws-cdk-lib"; | ||
import { GraphqlApi, MappingTemplate } from "aws-cdk-lib/aws-appsync"; | ||
import { IUserPool } from "aws-cdk-lib/aws-cognito"; | ||
import { Runtime } from "aws-cdk-lib/aws-lambda"; | ||
import { NodejsFunction } from "aws-cdk-lib/aws-lambda-nodejs"; | ||
import path from "path"; | ||
|
||
export function addCreateUserLambda({ | ||
name, | ||
stack, | ||
graphQL, | ||
userPool, | ||
}: { | ||
name: string; | ||
stack: Stack; | ||
graphQL: GraphqlApi; | ||
userPool: IUserPool; | ||
}) { | ||
const createUserLambda = new NodejsFunction(stack, `${name}-createUser`, { | ||
entry: path.resolve(__dirname, "..", "lambda-triggers", "create-user.js"), | ||
runtime: Runtime.NODEJS_18_X, | ||
environment: { | ||
USER_POOL_ID: userPool.userPoolId, | ||
}, | ||
}); | ||
userPool.grant( | ||
createUserLambda, | ||
"cognito-idp:AdminCreateUser", | ||
"cognito-idp:AdminSetUserPassword", | ||
"cognito-idp:AdminSetUserMFAPreference", | ||
"cognito-idp:AdminUpdateUserAttributes" | ||
); | ||
const createUserSource = graphQL.addLambdaDataSource( | ||
`${name}-GraphQLApiCreateUserLambda`, | ||
createUserLambda | ||
); | ||
createUserSource.createResolver(`${name}-MutationCreateUserResolver`, { | ||
typeName: "Mutation", | ||
fieldName: "createUser", | ||
requestMappingTemplate: MappingTemplate.lambdaRequest(), | ||
responseMappingTemplate: MappingTemplate.lambdaResult(), | ||
}); | ||
} |
Oops, something went wrong.