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): support emailVerified for AttributeMapping interface #31632

Merged
merged 12 commits into from
Oct 17, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ new UserPoolIdentityProviderApple(stack, 'apple', {
attributeMapping: {
familyName: ProviderAttribute.APPLE_LAST_NAME,
givenName: ProviderAttribute.APPLE_FIRST_NAME,
emailVerified: ProviderAttribute.APPLE_EMAIL_VERIFIED,
},
});

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"given_name": "given_name",
"family_name": "family_name",
"email": "email",
"email_verified": "email_verified",
"gender": "gender",
"names": "names"
},
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ new UserPoolIdentityProviderGoogle(stack, 'google', {
givenName: ProviderAttribute.GOOGLE_GIVEN_NAME,
familyName: ProviderAttribute.GOOGLE_FAMILY_NAME,
email: ProviderAttribute.GOOGLE_EMAIL,
emailVerified: ProviderAttribute.GOOGLE_EMAIL_VERIFIED,
gender: ProviderAttribute.GOOGLE_GENDER,
custom: {
names: ProviderAttribute.GOOGLE_NAMES,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
"Type": "AWS::Cognito::UserPoolIdentityProvider",
"Properties": {
"AttributeMapping": {
"phone_number": "phone_number"
"phone_number": "phone_number",
"email_verified": "email_verified"
},
"ProviderDetails": {
"client_id": "client-id",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ new UserPoolIdentityProviderOidc(stack, 'cdk', {
scopes: ['openid', 'phone'],
attributeMapping: {
phoneNumber: ProviderAttribute.other('phone_number'),
emailVerified: ProviderAttribute.other('email_verified'),
},
});

Expand Down
18 changes: 18 additions & 0 deletions packages/aws-cdk-lib/aws-cognito/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1002,3 +1002,21 @@ const userpool = new cognito.UserPool(this, 'UserPool', {
```

By default deletion protection is disabled.


1### `email_verified` Attribute Mapping

If you use a third-party identity provider, you can specify the `email_verified` attribute in attributeMapping.

```typescript
const userpool = new cognito.UserPool(this, 'Pool');

new UserPoolIdentityProviderGoogle(stack, 'google', {
userPool: userpool,
clientId: 'google-client-id',
attributeMapping: {
email: ProviderAttribute.GOOGLE_EMAIL,
emailVerified: ProviderAttribute.GOOGLE_EMAIL_VERIFIED, // you can mapping the `email_verified` attribute.
},
});
```
10 changes: 10 additions & 0 deletions packages/aws-cdk-lib/aws-cognito/lib/user-pool-idps/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { IUserPool } from '../user-pool';
export class ProviderAttribute {
/** The email attribute provided by Apple */
public static readonly APPLE_EMAIL = new ProviderAttribute('email');
/** The email verified atribute provided by Apple */
public static readonly APPLE_EMAIL_VERIFIED = new ProviderAttribute('email_verified');
Comment on lines +9 to +10
Copy link
Contributor Author

Choose a reason for hiding this comment

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

/** The name attribute provided by Apple */
public static readonly APPLE_NAME = new ProviderAttribute('name');
/** The first name attribute provided by Apple */
Expand Down Expand Up @@ -51,6 +53,8 @@ export class ProviderAttribute {
public static readonly GOOGLE_PHONE_NUMBERS = new ProviderAttribute('phoneNumbers');
/** The email attribute provided by Google */
public static readonly GOOGLE_EMAIL = new ProviderAttribute('email');
/** The email verified attribute provided by Google */
public static readonly GOOGLE_EMAIL_VERIFIED = new ProviderAttribute('email_verified');
GavinZZ marked this conversation as resolved.
Show resolved Hide resolved
/** The name attribute provided by Google */
public static readonly GOOGLE_NAME = new ProviderAttribute('name');
/** The picture attribute provided by Google */
Expand Down Expand Up @@ -98,6 +102,12 @@ export interface AttributeMapping {
*/
readonly email?: ProviderAttribute;

/**
* The user's e-mail address is verification.
* @default - not mapped
*/
readonly emailVerified?: ProviderAttribute;

/**
* The surname or last name of user.
* @default - not mapped
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ describe('UserPoolIdentityProvider', () => {
attributeMapping: {
familyName: ProviderAttribute.APPLE_LAST_NAME,
givenName: ProviderAttribute.APPLE_FIRST_NAME,
emailVerified: ProviderAttribute.APPLE_EMAIL_VERIFIED,
custom: {
customAttr1: ProviderAttribute.APPLE_EMAIL,
customAttr2: ProviderAttribute.other('sub'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ describe('UserPoolIdentityProvider', () => {
expect(idp.mapping).toStrictEqual({
given_name: 'name',
birthdate: 'birthday',
email_verified: 'email_verified',
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ describe('UserPoolIdentityProvider', () => {
attributeMapping: {
givenName: ProviderAttribute.GOOGLE_NAME,
address: ProviderAttribute.other('google-address'),
emailVerified: ProviderAttribute.GOOGLE_EMAIL_VERIFIED,
custom: {
customAttr1: ProviderAttribute.GOOGLE_EMAIL,
customAttr2: ProviderAttribute.other('google-custom-attr'),
Expand Down