@@ -213,6 +213,65 @@ pub struct CognitoEventUserPoolsPreTokenGenResponse {
213
213
pub claims_override_details : Option < ClaimsOverrideDetails > ,
214
214
}
215
215
216
+ /// `CognitoEventUserPoolsPreTokenGenV2` is sent by AWS Cognito User Pools when a user attempts to retrieve
217
+ /// credentials, allowing a Lambda to perform insert, suppress or override claims. This is the Version 2 Payload
218
+ #[ derive( Clone , Debug , Default , Deserialize , Eq , PartialEq , Serialize ) ]
219
+ #[ serde( rename_all = "camelCase" ) ]
220
+ pub struct CognitoEventUserPoolsPreTokenGenV2 {
221
+ #[ serde( rename = "CognitoEventUserPoolsHeader" ) ]
222
+ #[ serde( flatten) ]
223
+ pub cognito_event_user_pools_header : CognitoEventUserPoolsHeader ,
224
+ pub request : CognitoEventUserPoolsPreTokenGenRequestV2 ,
225
+ pub response : CognitoEventUserPoolsPreTokenGenResponseV2 ,
226
+ }
227
+
228
+ /// `CognitoEventUserPoolsPreTokenGenRequestV2` contains request portion of PreTokenGenV2 event
229
+ #[ derive( Clone , Debug , Default , Deserialize , Eq , PartialEq , Serialize ) ]
230
+ #[ serde( rename_all = "camelCase" ) ]
231
+ pub struct CognitoEventUserPoolsPreTokenGenRequestV2 {
232
+ #[ serde( deserialize_with = "deserialize_lambda_map" ) ]
233
+ #[ serde( default ) ]
234
+ pub user_attributes : HashMap < String , String > ,
235
+ pub group_configuration : GroupConfiguration ,
236
+ #[ serde( deserialize_with = "deserialize_lambda_map" ) ]
237
+ #[ serde( default ) ]
238
+ pub client_metadata : HashMap < String , String > ,
239
+ pub scopes : Vec < String > ,
240
+ }
241
+
242
+ #[ derive( Clone , Debug , Default , Deserialize , Eq , PartialEq , Serialize ) ]
243
+ #[ serde( rename_all = "camelCase" ) ]
244
+ pub struct CognitoEventUserPoolsPreTokenGenResponseV2 {
245
+ pub claims_and_scope_override_details : Option < ClaimsAndScopeOverrideDetailsV2 > ,
246
+ }
247
+
248
+ /// `ClaimsAndScopeOverrideDetailsV2` allows lambda to add, suppress or override claims in the token
249
+ #[ derive( Clone , Debug , Default , Deserialize , Eq , PartialEq , Serialize ) ]
250
+ #[ serde( rename_all = "camelCase" ) ]
251
+ pub struct ClaimsAndScopeOverrideDetailsV2 {
252
+ pub group_override_details : GroupConfiguration ,
253
+ pub id_token_generation : Option < CognitoIdTokenGenerationV2 > ,
254
+ pub access_token_generation : Option < CognitoAccessTokenGenerationV2 > ,
255
+ }
256
+
257
+ /// `CognitoIdTokenGenerationV2` allows lambda to customize the ID Token before generation
258
+ #[ derive( Clone , Debug , Default , Deserialize , Eq , PartialEq , Serialize ) ]
259
+ #[ serde( rename_all = "camelCase" ) ]
260
+ pub struct CognitoIdTokenGenerationV2 {
261
+ pub claims_to_add_or_override : HashMap < String , String > ,
262
+ pub claims_to_suppress : Vec < String > ,
263
+ }
264
+
265
+ /// `CognitoAccessTokenGenerationV2` allows lambda to customize the Access Token before generation
266
+ #[ derive( Clone , Debug , Default , Deserialize , Eq , PartialEq , Serialize ) ]
267
+ #[ serde( rename_all = "camelCase" ) ]
268
+ pub struct CognitoAccessTokenGenerationV2 {
269
+ pub claims_to_add_or_override : HashMap < String , String > ,
270
+ pub claims_to_suppress : Vec < String > ,
271
+ pub scopes_to_add : Vec < String > ,
272
+ pub scopes_to_suppress : Vec < String > ,
273
+ }
274
+
216
275
/// `CognitoEventUserPoolsPostAuthenticationRequest` contains the request portion of a PostAuthentication event
217
276
#[ derive( Clone , Debug , Default , Deserialize , Eq , PartialEq , Serialize ) ]
218
277
#[ serde( rename_all = "camelCase" ) ]
@@ -608,6 +667,16 @@ mod test {
608
667
assert_eq ! ( parsed, reparsed) ;
609
668
}
610
669
670
+ #[ test]
671
+ #[ cfg( feature = "cognito" ) ]
672
+ fn example_cognito_event_userpools_pretokengen_v2_incoming ( ) {
673
+ let data = include_bytes ! ( "../../fixtures/example-cognito-event-userpools-pretokengen-v2-incoming.json" ) ;
674
+ let parsed: CognitoEventUserPoolsPreTokenGenV2 = serde_json:: from_slice ( data) . unwrap ( ) ;
675
+ let output: String = serde_json:: to_string ( & parsed) . unwrap ( ) ;
676
+ let reparsed: CognitoEventUserPoolsPreTokenGenV2 = serde_json:: from_slice ( output. as_bytes ( ) ) . unwrap ( ) ;
677
+ assert_eq ! ( parsed, reparsed) ;
678
+ }
679
+
611
680
#[ test]
612
681
#[ cfg( feature = "cognito" ) ]
613
682
fn example_cognito_event_userpools_pretokengen ( ) {
@@ -618,6 +687,16 @@ mod test {
618
687
assert_eq ! ( parsed, reparsed) ;
619
688
}
620
689
690
+ #[ test]
691
+ #[ cfg( feature = "cognito" ) ]
692
+ fn example_cognito_event_userpools_v2_pretokengen ( ) {
693
+ let data = include_bytes ! ( "../../fixtures/example-cognito-event-userpools-pretokengen-v2.json" ) ;
694
+ let parsed: CognitoEventUserPoolsPreTokenGenV2 = serde_json:: from_slice ( data) . unwrap ( ) ;
695
+ let output: String = serde_json:: to_string ( & parsed) . unwrap ( ) ;
696
+ let reparsed: CognitoEventUserPoolsPreTokenGenV2 = serde_json:: from_slice ( output. as_bytes ( ) ) . unwrap ( ) ;
697
+ assert_eq ! ( parsed, reparsed) ;
698
+ }
699
+
621
700
#[ test]
622
701
#[ cfg( feature = "cognito" ) ]
623
702
fn example_cognito_event_userpools_verify_auth_challenge ( ) {
0 commit comments