Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cognito): choice-based authentication (passwordless sign-in / passkey sign-in) #32369

Merged
merged 26 commits into from
Feb 13, 2025

Conversation

Tietew
Copy link
Contributor

@Tietew Tietew commented Dec 3, 2024

Issue # (if applicable)

Closes #32265.

Reason for this change

User Pool has introduced choice-based authentication, including passwordless sign-in and passkey (WebAuthn) sign-in.
For details, see Manage authentication methods in AWS SDKs.

Related PRs:

Description of changes

Added following properties:

  • allowedFirstAuthFactors - allowed first authenticate factors
  • passkeyRelyingPartyId - the authentication domain used as passkey relying party ID
  • passkeyUserVerification - configure user verification to be preferred or required

Description of how you validated changes

Added unit test and an integ test.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions bot added admired-contributor [Pilot] contributed between 13-24 PRs to the CDK effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 labels Dec 3, 2024
@aws-cdk-automation aws-cdk-automation requested a review from a team December 3, 2024 06:47
@Tietew

This comment was marked as resolved.

Copy link

codecov bot commented Dec 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.00%. Comparing base (b11f663) to head (b8b00ef).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #32369   +/-   ##
=======================================
  Coverage   81.00%   81.00%           
=======================================
  Files         238      238           
  Lines       14269    14269           
  Branches     2492     2492           
=======================================
  Hits        11558    11558           
  Misses       2425     2425           
  Partials      286      286           
Flag Coverage Δ
suite.unit 81.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
packages/aws-cdk 79.92% <ø> (ø)
packages/aws-cdk-lib/core 82.16% <ø> (ø)

@Tietew Tietew force-pushed the cognito-userpool-passwordless branch from 0d5449e to 53ffbfb Compare December 6, 2024 04:07
@Tietew Tietew changed the title feat(cognito): passwordless sign-in feat(cognito): choice-based authentication (passwordless sign-in / passkey sign-in) Dec 6, 2024
GavinZZ pushed a commit that referenced this pull request Dec 6, 2024
### Issue # (if applicable)

N/A

### Reason for this change

Amazon Cognito introduces the feature plans which replaces the Advanced
Security Mode.
See:
https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-sign-in-feature-plans.html

Related to #32369 - passwordless sign-in requires Essentials or higher
feature plan.

### Description of changes

- Add new `featurePlan` property and `FeaturePlan` enum to specify user
pool feature plan.
- Deprecate `advancedSecurityMode` property and `AdvancedSecurityMode`
enum.

Note that the previous AWS document about Advanced Security Mode is now
redirected to [Advanced security with threat
protection](https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pool-settings-threat-protection.html).

### Description of how you validated changes

Added new unit tests and an integ test.

### Checklist
- [x] My code adheres to the [CONTRIBUTING
GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and
[DESIGN
GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache-2.0 license*

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
@Tietew Tietew marked this pull request as ready for review December 7, 2024 03:17
@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Dec 7, 2024
Copy link
Contributor

@lpizzinidev lpizzinidev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Sorry for the super-late review

@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jan 28, 2025
@Tietew
Copy link
Contributor Author

Tietew commented Jan 30, 2025

@lpizzinidev Thank you for your comments! I've pushed some modifications.

Copy link
Contributor

@lpizzinidev lpizzinidev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My idea was to enforce password: true regardless when setting allowedFirstAuthFactors. Please let me know what's your thought 👍

packages/aws-cdk-lib/aws-cognito/lib/user-pool.ts Outdated Show resolved Hide resolved
packages/aws-cdk-lib/aws-cognito/lib/user-pool.ts Outdated Show resolved Hide resolved
packages/aws-cdk-lib/aws-cognito/lib/user-pool.ts Outdated Show resolved Hide resolved
Comment on lines 1446 to 1453
/*
* Choice-based authentication is enabled when built allowedFirstAuthFactors contains any factor but PASSWORD.
* This check should be placed here to supply the way to disable choice-based authentication explicitly
* by specifying `allowedFirstAuthFactors: { password: true }`.
*/
const isChouseBasedAuthenticationEnabled = allowedFirstAuthFactors.some((auth) => auth !== 'PASSWORD');
if (isChouseBasedAuthenticationEnabled && props.featurePlan === FeaturePlan.LITE) {
throw new ValidationError('To enable choice-based authentication, set `featurePlan` to `FeaturePlan.ESSENTIALS` or `FeaturePlan.PLUS`.', this);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/*
* Choice-based authentication is enabled when built allowedFirstAuthFactors contains any factor but PASSWORD.
* This check should be placed here to supply the way to disable choice-based authentication explicitly
* by specifying `allowedFirstAuthFactors: { password: true }`.
*/
const isChouseBasedAuthenticationEnabled = allowedFirstAuthFactors.some((auth) => auth !== 'PASSWORD');
if (isChouseBasedAuthenticationEnabled && props.featurePlan === FeaturePlan.LITE) {
throw new ValidationError('To enable choice-based authentication, set `featurePlan` to `FeaturePlan.ESSENTIALS` or `FeaturePlan.PLUS`.', this);
if (props.featurePlan === FeaturePlan.LITE) {
throw new ValidationError('To enable choice-based authentication, set `featurePlan` to `FeaturePlan.ESSENTIALS` or `FeaturePlan.PLUS`.', this);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allowedFirstAuthFactors: { password: true } must allow Lite feature plan.

When the user have a user pool with choice-based authentication enabled and want to downgrade to Lite feature plan, the user must specify allowedFirstAuthFactors: { password: true } to disable choice-based authentication explicitly.
see #32369 (comment)

@Tietew
Copy link
Contributor Author

Tietew commented Feb 4, 2025

@lpizzinidev Thank you for explanation. I misunderstood.

When Cognito supports to disable password authentication in the future,
the password option should default to false...

Copy link
Contributor

@lpizzinidev lpizzinidev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Feb 8, 2025
@samson-keung samson-keung self-assigned this Feb 10, 2025
Copy link
Contributor

@samson-keung samson-keung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appreciate the contribution! Thank you.

Left some comments on the design of the construct props.

packages/aws-cdk-lib/aws-cognito/lib/user-pool.ts Outdated Show resolved Hide resolved
packages/aws-cdk-lib/aws-cognito/lib/user-pool.ts Outdated Show resolved Hide resolved
packages/aws-cdk-lib/aws-cognito/lib/user-pool.ts Outdated Show resolved Hide resolved
@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Feb 12, 2025
@Tietew
Copy link
Contributor Author

Tietew commented Feb 12, 2025

@samson-keung Than you for your review. I'm working on your suggestions.
Could you answer some questions I left, please?

@samson-keung
Copy link
Contributor

@samson-keung Than you for your review. I'm working on your suggestions. Could you answer some questions I left, please?

Responded within the threads. Sorry I wasn't able to get to them quicker as I am in the PDT time zone. Updated my profile to reflect that :)

Co-authored-by: Samson Keung <keungsi@amazon.com>
@mergify mergify bot dismissed samson-keung’s stale review February 13, 2025 02:33

Pull request has been modified.

@Tietew
Copy link
Contributor Author

Tietew commented Feb 13, 2025

@samson-keung I pushed updates. Time zone is not an issue. Thank you!

Copy link
Contributor

@samson-keung samson-keung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you for adding this feature!

Copy link
Contributor

mergify bot commented Feb 13, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: b8b00ef
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 9a6e5cc into aws:main Feb 13, 2025
20 checks passed
Copy link
Contributor

mergify bot commented Feb 13, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

Copy link

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 13, 2025
@Tietew Tietew deleted the cognito-userpool-passwordless branch February 14, 2025 00:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
admired-contributor [Pilot] contributed between 13-24 PRs to the CDK effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cognito: Passwordless authentication support
4 participants