-
Notifications
You must be signed in to change notification settings - Fork 820
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(auth): standardize CloudFormation trigger templates, prevent erro…
…rs at runtime (#7219) * fix: add-to-group PostConfirmation Lambda should not throw Co-authored-by: Colin Ihrig <[email protected]>
- Loading branch information
1 parent
753a737
commit f9796bd
Showing
24 changed files
with
152 additions
and
201 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
...ider-utils/awscloudformation/triggers/CreateAuthChallenge/boilerplate-create-challenge.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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
|
||
exports.handler = (event, context) => { | ||
exports.handler = async event => { | ||
if (event.request.session.length === 2 && event.request.challengeName === 'CUSTOM_CHALLENGE') { | ||
event.response.publicChallengeParameters = { trigger: 'true' }; | ||
|
||
event.response.privateChallengeParameters = {}; | ||
event.response.privateChallengeParameters.answer = process.env.CHALLENGEANSWER; | ||
} | ||
context.done(null, event); | ||
return event; | ||
}; |
4 changes: 2 additions & 2 deletions
4
...provider-utils/awscloudformation/triggers/CreateAuthChallenge/captcha-create-challenge.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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
|
||
exports.handler = (event, context) => { | ||
exports.handler = async event => { | ||
if (event.request.session.length === 2 && event.request.challengeName === 'CUSTOM_CHALLENGE') { | ||
event.response.publicChallengeParameters = { trigger: 'true' }; | ||
event.response.privateChallengeParameters = { answer: '' }; | ||
event.response.challengeMetadata = 'CAPTCHA_CHALLENGE'; | ||
} | ||
context.done(null, event); | ||
return event; | ||
}; |
14 changes: 0 additions & 14 deletions
14
...ils/awscloudformation/triggers/CreateAuthChallenge/function-template-dir/trigger-index.js
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
...der-utils/awscloudformation/triggers/CustomMessage/function-template-dir/trigger-index.js
This file was deleted.
Oops, something went wrong.
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
14 changes: 0 additions & 14 deletions
14
...ils/awscloudformation/triggers/DefineAuthChallenge/function-template-dir/trigger-index.js
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
...tils/awscloudformation/triggers/PostAuthentication/function-template-dir/trigger-index.js
This file was deleted.
Oops, something went wrong.
29 changes: 13 additions & 16 deletions
29
...-category-auth/provider-utils/awscloudformation/triggers/PostConfirmation/add-to-group.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 |
---|---|---|
@@ -1,34 +1,31 @@ | ||
/* eslint-disable-line */ const aws = require('aws-sdk'); | ||
|
||
exports.handler = async (event, context) => { | ||
const cognitoidentityserviceprovider = new aws.CognitoIdentityServiceProvider({ apiVersion: '2016-04-18' }); | ||
const cognitoidentityserviceprovider = new aws.CognitoIdentityServiceProvider({ | ||
apiVersion: '2016-04-18', | ||
}); | ||
|
||
exports.handler = async event => { | ||
const groupParams = { | ||
GroupName: process.env.GROUP, | ||
UserPoolId: event.userPoolId, | ||
}; | ||
|
||
const addUserParams = { | ||
GroupName: process.env.GROUP, | ||
UserPoolId: event.userPoolId, | ||
Username: event.userName, | ||
}; | ||
|
||
/** | ||
* Check if the group exists; if it doesn't, create it. | ||
*/ | ||
try { | ||
await cognitoidentityserviceprovider.getGroup(groupParams).promise(); | ||
} catch (e) { | ||
await cognitoidentityserviceprovider.createGroup(groupParams).promise(); | ||
} | ||
/** | ||
* Then, add the user to the group. | ||
*/ | ||
await cognitoidentityserviceprovider.adminAddUserToGroup(addUserParams).promise(); | ||
|
||
try { | ||
await cognitoidentityserviceprovider.adminAddUserToGroup(addUserParams).promise(); | ||
return { | ||
statusCode: 200, | ||
body: JSON.stringify(event) | ||
} | ||
} catch (error) { | ||
return { | ||
statusCode: 500, | ||
body: JSON.stringify(error) | ||
} | ||
} | ||
return event; | ||
}; |
14 changes: 0 additions & 14 deletions
14
...-utils/awscloudformation/triggers/PostConfirmation/function-template-dir/trigger-index.js
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
...utils/awscloudformation/triggers/PreAuthentication/function-template-dir/trigger-index.js
This file was deleted.
Oops, something went wrong.
8 changes: 4 additions & 4 deletions
8
...auth/provider-utils/awscloudformation/triggers/PreSignup/email-filter-allowlist-legacy.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 |
---|---|---|
@@ -1,13 +1,13 @@ | ||
exports.handler = (event, context, callback) => { | ||
exports.handler = async event => { | ||
// allowed domains | ||
const ald = process.env.DOMAINWHITELIST.split(',').map(d => d.trim()); | ||
|
||
const { email } = event.request.userAttributes; | ||
const domain = email.substring(email.indexOf('@') + 1); | ||
|
||
if (!ald.includes(domain)) { | ||
callback(new Error(`Invalid email domain: ${domain}`), event); | ||
} else { | ||
callback(null, event); | ||
throw new Error(`Invalid email domain: ${domain}`); | ||
} | ||
|
||
return event; | ||
}; |
8 changes: 4 additions & 4 deletions
8
...tegory-auth/provider-utils/awscloudformation/triggers/PreSignup/email-filter-allowlist.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 |
---|---|---|
@@ -1,13 +1,13 @@ | ||
exports.handler = (event, context, callback) => { | ||
exports.handler = async event => { | ||
// allowed domains | ||
const ald = process.env.DOMAINALLOWLIST.split(',').map(d => d.trim()); | ||
|
||
const { email } = event.request.userAttributes; | ||
const domain = email.substring(email.indexOf('@') + 1); | ||
|
||
if (!ald.includes(domain)) { | ||
callback(new Error(`Invalid email domain: ${domain}`), event); | ||
} else { | ||
callback(null, event); | ||
throw new Error(`Invalid email domain: ${domain}`); | ||
} | ||
|
||
return event; | ||
}; |
8 changes: 4 additions & 4 deletions
8
...-auth/provider-utils/awscloudformation/triggers/PreSignup/email-filter-denylist-legacy.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 |
---|---|---|
@@ -1,13 +1,13 @@ | ||
exports.handler = (event, context, callback) => { | ||
exports.handler = async event => { | ||
// disallowed domains | ||
const dld = process.env.DOMAINBLACKLIST.split(',').map(d => d.trim()); | ||
|
||
const { email } = event.request.userAttributes; | ||
const domain = email.substring(email.indexOf('@') + 1); | ||
|
||
if (dld.includes(domain)) { | ||
callback(new Error(`Invalid email domain: ${domain}`), event); | ||
} else { | ||
callback(null, event); | ||
throw new Error(`Invalid email domain: ${domain}`); | ||
} | ||
|
||
return event; | ||
}; |
8 changes: 4 additions & 4 deletions
8
...ategory-auth/provider-utils/awscloudformation/triggers/PreSignup/email-filter-denylist.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 |
---|---|---|
@@ -1,13 +1,13 @@ | ||
exports.handler = (event, context, callback) => { | ||
exports.handler = async event => { | ||
// disallowed domains | ||
const dld = process.env.DOMAINDENYLIST.split(',').map(d => d.trim()); | ||
|
||
const { email } = event.request.userAttributes; | ||
const domain = email.substring(email.indexOf('@') + 1); | ||
|
||
if (dld.includes(domain)) { | ||
callback(new Error(`Invalid email domain: ${domain}`), event); | ||
} else { | ||
callback(null, event); | ||
throw new Error(`Invalid email domain: ${domain}`); | ||
} | ||
|
||
return event; | ||
}; |
14 changes: 0 additions & 14 deletions
14
...rovider-utils/awscloudformation/triggers/PreSignup/function-template-dir/trigger-index.js
This file was deleted.
Oops, something went wrong.
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
14 changes: 0 additions & 14 deletions
14
...tils/awscloudformation/triggers/PreTokenGeneration/function-template-dir/trigger-index.js
This file was deleted.
Oops, something went wrong.
5 changes: 3 additions & 2 deletions
5
...ovider-utils/awscloudformation/triggers/VerifyAuthChallengeResponse/boilerplate-verify.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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
exports.handler = (event, context) => { | ||
exports.handler = async event => { | ||
if (event.request.privateChallengeParameters.answer === event.request.challengeAnswer) { | ||
event.response.answerCorrect = true; | ||
} else { | ||
event.response.answerCorrect = false; | ||
} | ||
context.done(null, event); | ||
|
||
return event; | ||
}; |
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
Oops, something went wrong.