@@ -14,120 +14,14 @@ export interface IUserPoolIdentityProvider extends IResource {
14
14
}
15
15
16
16
/**
17
- * The options to create a new UserPoolIdentityProvider for a given UserPool.
17
+ * Properties to initialize UserPoolFacebookIdentityProvider
18
18
*/
19
- export interface UserPoolIdentityProviderOptions {
19
+ export interface UserPoolFacebookIdentityProviderProps {
20
20
/**
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.
38
22
*/
39
23
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
- }
126
24
127
- /**
128
- * Options to integrate with 'Facebook Login'.
129
- */
130
- export interface FacebookProviderOptions {
131
25
/**
132
26
* The client id recognized by Facebook APIs.
133
27
*/
@@ -151,29 +45,42 @@ export interface FacebookProviderOptions {
151
45
}
152
46
153
47
/**
154
- * Options to integrate with 'Google Sign in'.
48
+ * Represents a identity provider that integrates with 'Facebook Login'
49
+ * @resource AWS::Cognito::UserPoolIdentityProvider
155
50
*/
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
+ }
171
73
}
172
74
173
75
/**
174
- * Options to integrate with 'Login with Amazon'.
76
+ * Properties to initialize UserPoolAmazonIdentityProvider
175
77
*/
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
+
177
84
/**
178
85
* The client id recognized by 'Login with Amazon' APIs.
179
86
* @see https://developer.amazon.com/docs/login-with-amazon/security-profile.html#client-identifier
@@ -193,9 +100,41 @@ export interface AmazonProviderOptions {
193
100
}
194
101
195
102
/**
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
197
131
*/
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
+
199
138
/**
200
139
* The Services id received when the 'Sign in with Apple' client was created.
201
140
*/
@@ -221,23 +160,61 @@ export interface AppleProviderOptions {
221
160
}
222
161
223
162
/**
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
226
165
*/
227
- export class UserPoolIdentityProvider extends Resource implements IUserPoolIdentityProvider {
166
+ export class UserPoolAppleIdentityProvider extends Resource implements IUserPoolIdentityProvider {
228
167
public readonly providerName : string ;
229
168
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' ] ;
234
173
235
174
const resource = new CfnUserPoolIdentityProvider ( this , 'Resource' , {
236
- providerName : this . physicalName ,
237
175
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
+ } ,
240
185
} ) ;
186
+
241
187
this . providerName = super . getResourceNameAttribute ( resource . ref ) ;
242
188
}
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 ( ) { }
243
220
}
0 commit comments