Skip to content

Commit b3533a3

Browse files
author
Niranjan Jayakar
committed
overhaul - rev2
1 parent 287aa8b commit b3533a3

7 files changed

+363
-359
lines changed

packages/@aws-cdk/aws-cognito/lib/user-pool-idp.ts

+116-139
Original file line numberDiff line numberDiff line change
@@ -14,120 +14,14 @@ export interface IUserPoolIdentityProvider extends IResource {
1414
}
1515

1616
/**
17-
* The options to create a new UserPoolIdentityProvider for a given UserPool.
17+
* Properties to initialize UserPoolFacebookIdentityProvider
1818
*/
19-
export interface UserPoolIdentityProviderOptions {
19+
export interface UserPoolFacebookIdentityProviderProps {
2020
/**
21-
* The name of this provider. This will be its primary identifier.
22-
*/
23-
readonly userPoolIdentityProviderName: string;
24-
25-
/**
26-
* Options to integrate with third party social identity providers such as Facebook, Google, Amazon and Apple.
27-
* @see https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-identity-provider.html#cognito-user-pools-facebook-provider
28-
*/
29-
readonly socialIdentity: SocialIdentityProvider;
30-
}
31-
32-
/**
33-
* The properties to initialize a new UserPoolIdentityProvider
34-
*/
35-
export interface UserPoolIdentityProviderProps extends UserPoolIdentityProviderOptions {
36-
/**
37-
* The user pool to whom this provider is attached to.
21+
* The user pool to which this construct provides identities.
3822
*/
3923
readonly userPool: IUserPool;
40-
}
41-
42-
/**
43-
* Options to integrate with the various social identity providers.
44-
*/
45-
export class SocialIdentityProvider {
46-
/**
47-
* Federate with 'Facebook Login'
48-
* @see https://developers.facebook.com/docs/facebook-login/
49-
*/
50-
public static facebook(options: FacebookProviderOptions) {
51-
const scopes = options.scopes ?? [ 'public_profile' ];
52-
return new SocialIdentityProvider('Facebook', {
53-
client_id: options.clientId,
54-
client_secret: options.clientSecret,
55-
authorize_scopes: scopes.join(','),
56-
api_version: options.apiVersion,
57-
});
58-
}
59-
60-
/**
61-
* Federate with 'Google Sign In'
62-
* @see https://developers.google.com/identity/
63-
*/
64-
public static google(options: GoogleProviderOptions) {
65-
const scopes = options.scopes ?? [ 'profile', 'email', 'openid' ];
66-
return new SocialIdentityProvider('Google', {
67-
client_id: options.clientId,
68-
client_secret: options.clientSecret,
69-
authorize_scopes: scopes.join(' '),
70-
});
71-
}
72-
73-
/**
74-
* Federate with 'Login with Amazon'
75-
* @see https://developer.amazon.com/apps-and-games/login-with-amazon
76-
*/
77-
public static amazon(options: AmazonProviderOptions) {
78-
const scopes = options.scopes ?? [ 'profile' ];
79-
return new SocialIdentityProvider('LoginWithAmazon', {
80-
client_id: options.clientId,
81-
client_secret: options.clientSecret,
82-
authorize_scopes: scopes.join(' '),
83-
});
84-
}
85-
86-
/**
87-
* Federate with 'Sign in with Apple'
88-
* @see https://developer.apple.com/sign-in-with-apple/
89-
*/
90-
public static apple(options: AppleProviderOptions) {
91-
const scopes = options.scopes ?? [ 'public_profile', 'email' ];
92-
return new SocialIdentityProvider('SignInWithApple', {
93-
client_id: options.servicesId,
94-
team_id: options.teamId,
95-
key_id: options.keyId,
96-
private_key: options.privateKey,
97-
authorize_scopes: scopes.join(' '),
98-
});
99-
}
100-
101-
/**
102-
* Custom configuration that is not yet supported by the CDK.
103-
*/
104-
public static custom(providerType: string, providerDetails: { [key: string]: any }) {
105-
return new SocialIdentityProvider(providerType, providerDetails);
106-
}
107-
108-
// tslint:disable:max-line-length
109-
/**
110-
* The type of the provider as recognized by CloudFormation
111-
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cognito-userpoolidentityprovider.html#cfn-cognito-userpoolidentityprovider-providertype
112-
*/
113-
public readonly providerType: string;
114-
/**
115-
* The properties needed to connect to the provider as recognized by CloudFormation
116-
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cognito-userpoolidentityprovider.html#cfn-cognito-userpoolidentityprovider-providerdetails
117-
*/
118-
public readonly providerDetails: { [key: string]: any };
119-
// tslint:enable
120-
121-
private constructor(providerType: string, providerDetails: { [key: string]: any }) {
122-
this.providerType = providerType;
123-
this.providerDetails = providerDetails;
124-
}
125-
}
12624

127-
/**
128-
* Options to integrate with 'Facebook Login'.
129-
*/
130-
export interface FacebookProviderOptions {
13125
/**
13226
* The client id recognized by Facebook APIs.
13327
*/
@@ -151,29 +45,42 @@ export interface FacebookProviderOptions {
15145
}
15246

15347
/**
154-
* Options to integrate with 'Google Sign in'.
48+
* Represents a identity provider that integrates with 'Facebook Login'
49+
* @resource AWS::Cognito::UserPoolIdentityProvider
15550
*/
156-
export interface GoogleProviderOptions {
157-
/**
158-
* The client id recognized by 'Google Sign in'.
159-
*/
160-
readonly clientId: string;
161-
/**
162-
* The client secret to be accompanied with clientId for Google to authenticate the client.
163-
*/
164-
readonly clientSecret: string;
165-
/**
166-
* The list of Google permissions to obtain for getting access to the Google profile.
167-
* @see https://developers.google.com/identity/protocols/oauth2/scopes
168-
* @default [ profile, email, openid ]
169-
*/
170-
readonly scopes?: string[];
51+
export class UserPoolFacebookIdentityProvider extends Resource implements IUserPoolIdentityProvider {
52+
public readonly providerName: string;
53+
54+
constructor(scope: Construct, id: string, props: UserPoolFacebookIdentityProviderProps) {
55+
super(scope, id);
56+
57+
const scopes = props.scopes ?? [ 'public_profile' ];
58+
59+
const resource = new CfnUserPoolIdentityProvider(this, 'Resource', {
60+
userPoolId: props.userPool.userPoolId,
61+
providerName: 'Facebook', // must be 'Facebook' when the type is 'Facebook'
62+
providerType: 'Facebook',
63+
providerDetails: {
64+
client_id: props.clientId,
65+
client_secret: props.clientSecret,
66+
authorize_scopes: scopes.join(','),
67+
api_version: props.apiVersion,
68+
},
69+
});
70+
71+
this.providerName = super.getResourceNameAttribute(resource.ref);
72+
}
17173
}
17274

17375
/**
174-
* Options to integrate with 'Login with Amazon'.
76+
* Properties to initialize UserPoolAmazonIdentityProvider
17577
*/
176-
export interface AmazonProviderOptions {
78+
export interface UserPoolAmazonIdentityProviderProps {
79+
/**
80+
* The user pool to which this construct provides identities.
81+
*/
82+
readonly userPool: IUserPool;
83+
17784
/**
17885
* The client id recognized by 'Login with Amazon' APIs.
17986
* @see https://developer.amazon.com/docs/login-with-amazon/security-profile.html#client-identifier
@@ -193,9 +100,41 @@ export interface AmazonProviderOptions {
193100
}
194101

195102
/**
196-
* Options to integrate with 'Sign in with Apple'.
103+
* Represents a identity provider that integrates with 'Login with Amazon'
104+
* @resource AWS::Cognito::UserPoolIdentityProvider
105+
*/
106+
export class UserPoolAmazonIdentityProvider extends Resource implements IUserPoolIdentityProvider {
107+
public readonly providerName: string;
108+
109+
constructor(scope: Construct, id: string, props: UserPoolAmazonIdentityProviderProps) {
110+
super(scope, id);
111+
112+
const scopes = props.scopes ?? [ 'profile' ];
113+
114+
const resource = new CfnUserPoolIdentityProvider(this, 'Resource', {
115+
userPoolId: props.userPool.userPoolId,
116+
providerName: 'LoginWithAmazon', // must be 'LoginWithAmazon' when the type is 'LoginWithAmazon'
117+
providerType: 'LoginWithAmazon',
118+
providerDetails: {
119+
client_id: props.clientId,
120+
client_secret: props.clientSecret,
121+
authorize_scopes: scopes.join(' '),
122+
},
123+
});
124+
125+
this.providerName = super.getResourceNameAttribute(resource.ref);
126+
}
127+
}
128+
129+
/**
130+
* Properties to initialize UserPoolAppleIdentityProvider
197131
*/
198-
export interface AppleProviderOptions {
132+
export interface UserPoolAppleIdentityProviderProps {
133+
/**
134+
* The user pool to which this construct provides identities.
135+
*/
136+
readonly userPool: IUserPool;
137+
199138
/**
200139
* The Services id received when the 'Sign in with Apple' client was created.
201140
*/
@@ -221,23 +160,61 @@ export interface AppleProviderOptions {
221160
}
222161

223162
/**
224-
* Define a identity provider for a user pool.
225-
* @see https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-identity-provider.html
163+
* Represents a identity provider that integrates with 'Login with Amazon'
164+
* @resource AWS::Cognito::UserPoolIdentityProvider
226165
*/
227-
export class UserPoolIdentityProvider extends Resource implements IUserPoolIdentityProvider {
166+
export class UserPoolAppleIdentityProvider extends Resource implements IUserPoolIdentityProvider {
228167
public readonly providerName: string;
229168

230-
constructor(scope: Construct, id: string, props: UserPoolIdentityProviderProps) {
231-
super(scope, id, {
232-
physicalName: props.userPoolIdentityProviderName,
233-
});
169+
constructor(scope: Construct, id: string, props: UserPoolAppleIdentityProviderProps) {
170+
super(scope, id);
171+
172+
const scopes = props.scopes ?? [ 'public_profile', 'email' ];
234173

235174
const resource = new CfnUserPoolIdentityProvider(this, 'Resource', {
236-
providerName: this.physicalName,
237175
userPoolId: props.userPool.userPoolId,
238-
providerType: props.socialIdentity.providerType,
239-
providerDetails: props.socialIdentity.providerDetails,
176+
providerName: 'SignInWithApple', // must be 'SignInWithApple' when the type is 'SignInWithApple'
177+
providerType: 'SignInWithApple',
178+
providerDetails: {
179+
client_id: props.servicesId,
180+
team_id: props.teamId,
181+
key_id: props.keyId,
182+
private_key: props.privateKey,
183+
authorize_scopes: scopes.join(' '),
184+
},
240185
});
186+
241187
this.providerName = super.getResourceNameAttribute(resource.ref);
242188
}
189+
}
190+
191+
/**
192+
* Options to integrate with the various social identity providers.
193+
*/
194+
export class UserPoolIdentityProvider {
195+
/**
196+
* Federate with 'Facebook Login'
197+
* @see https://developers.facebook.com/docs/facebook-login/
198+
*/
199+
public static facebook(scope: Construct, id: string, options: UserPoolFacebookIdentityProviderProps) {
200+
return new UserPoolFacebookIdentityProvider(scope, id, options);
201+
}
202+
203+
/**
204+
* Federate with 'Login with Amazon'
205+
* @see https://developer.amazon.com/apps-and-games/login-with-amazon
206+
*/
207+
public static amazon(scope: Construct, id: string, options: UserPoolAmazonIdentityProviderProps) {
208+
return new UserPoolAmazonIdentityProvider(scope, id, options);
209+
}
210+
211+
/**
212+
* Federate with 'Sign in with Apple'
213+
* @see https://developer.apple.com/sign-in-with-apple/
214+
*/
215+
public static apple(scope: Construct, id: string, options: UserPoolAppleIdentityProviderProps) {
216+
return new UserPoolAppleIdentityProvider(scope, id, options);
217+
}
218+
219+
private constructor() {}
243220
}

packages/@aws-cdk/aws-cognito/lib/user-pool.ts

-12
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { CfnUserPool } from './cognito.generated';
55
import { ICustomAttribute, RequiredAttributes } from './user-pool-attr';
66
import { IUserPoolClient, UserPoolClient, UserPoolClientOptions } from './user-pool-client';
77
import { UserPoolDomain, UserPoolDomainOptions } from './user-pool-domain';
8-
import { UserPoolIdentityProvider, UserPoolIdentityProviderOptions } from './user-pool-idp';
98

109
/**
1110
* The different ways in which users of this pool can sign up or sign in.
@@ -682,17 +681,6 @@ export class UserPool extends Resource implements IUserPool {
682681
});
683682
}
684683

685-
/**
686-
* Associated a identity provider to this user pool
687-
* @see https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-identity-federation.html
688-
*/
689-
public addIdentityProvider(id: string, options: UserPoolIdentityProviderOptions): UserPoolIdentityProvider {
690-
return new UserPoolIdentityProvider(this, id, {
691-
userPool: this,
692-
...options,
693-
});
694-
}
695-
696684
private addLambdaPermission(fn: lambda.IFunction, name: string): void {
697685
const capitalize = name.charAt(0).toUpperCase() + name.slice(1);
698686
fn.addPermission(`${capitalize}Cognito`, {

packages/@aws-cdk/aws-cognito/package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@
9696
"exclude": [
9797
"attribute-tag:@aws-cdk/aws-cognito.UserPoolClient.userPoolClientName",
9898
"resource-attribute:@aws-cdk/aws-cognito.UserPoolClient.userPoolClientClientSecret",
99-
"props-physical-name:@aws-cdk/aws-cognito.UserPoolDomainProps"
99+
"props-physical-name:@aws-cdk/aws-cognito.UserPoolDomainProps",
100+
"props-physical-name:@aws-cdk/aws-cognito.UserPoolFacebookIdentityProviderProps",
101+
"props-physical-name:@aws-cdk/aws-cognito.UserPoolAmazonIdentityProviderProps",
102+
"props-physical-name:@aws-cdk/aws-cognito.UserPoolAppleIdentityProviderProps"
100103
]
101104
},
102105
"stability": "experimental",

packages/@aws-cdk/aws-cognito/test/integ.user-pool-idp-social.ts

-15
This file was deleted.

0 commit comments

Comments
 (0)