-
Notifications
You must be signed in to change notification settings - Fork 436
feat(parser): Added Cognito trigger schemas #6737
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
Merged
leandrodamascena
merged 11 commits into
aws-powertools:develop
from
VatsalGoel3:feat/parser-cognito-schemas-fix
Jul 9, 2025
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
155d114
feat(parser): Added Cognito trigger schemas
VatsalGoel3 03e520b
Updated docs
VatsalGoel3 de99934
Merge branch 'develop' into feat/parser-cognito-schemas-fix
leandrodamascena 8998d6a
Merge branch 'develop' into feat/parser-cognito-schemas-fix
VatsalGoel3 49c2bd8
Merge branch 'develop' into feat/parser-cognito-schemas-fix
leandrodamascena e3446d0
Merge branch 'develop' into feat/parser-cognito-schemas-fix
leandrodamascena adbe347
Fix Ruff problems
leandrodamascena e4aa97c
Fix implementation and tests
leandrodamascena 84c0ae3
Fix implementation and tests
leandrodamascena bb8ba50
Fix implementation and tests
leandrodamascena 281a55a
Fix docs
leandrodamascena File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
231 changes: 231 additions & 0 deletions
231
aws_lambda_powertools/utilities/parser/models/cognito.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,231 @@ | ||
from typing import Any, Dict, List, Literal, Optional | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
# Common context model for Cognito triggers | ||
class CognitoCallerContextModel(BaseModel): | ||
awsSdkVersion: str | ||
clientId: str | ||
|
||
|
||
# Base model for all Cognito triggers | ||
class CognitoTriggerBaseSchema(BaseModel): | ||
version: str | ||
region: str | ||
userPoolId: str | ||
userName: Optional[str] = None | ||
callerContext: CognitoCallerContextModel | ||
|
||
|
||
# Models for Pre-Signup flow | ||
class CognitoPreSignupRequestModel(BaseModel): | ||
userAttributes: Dict[str, Any] | ||
validationData: Optional[Dict[str, Any]] = None | ||
clientMetadata: Optional[Dict[str, Any]] = None | ||
userNotFound: Optional[bool] = None | ||
|
||
|
||
class CognitoPreSignupResponseModel(BaseModel): | ||
autoConfirmUser: Optional[bool] = False | ||
autoVerifyPhone: Optional[bool] = False | ||
autoVerifyEmail: Optional[bool] = False | ||
|
||
|
||
class CognitoPreSignupTriggerModel(CognitoTriggerBaseSchema): | ||
triggerSource: Literal["PreSignUp_SignUp"] | ||
request: CognitoPreSignupRequestModel | ||
response: CognitoPreSignupResponseModel | ||
|
||
|
||
# Models for Post-Confirmation flow | ||
class CognitoPostConfirmationRequestModel(BaseModel): | ||
userAttributes: Dict[str, Any] | ||
clientMetadata: Optional[Dict[str, Any]] = None | ||
|
||
|
||
class CognitoPostConfirmationTriggerModel(CognitoTriggerBaseSchema): | ||
triggerSource: Literal["PostConfirmation_ConfirmSignUp"] | ||
request: CognitoPostConfirmationRequestModel | ||
response: Dict[str, Any] = {} | ||
|
||
|
||
# Models for Pre-Authentication flow | ||
class CognitoPreAuthenticationRequestModel(BaseModel): | ||
userAttributes: Dict[str, Any] | ||
validationData: Optional[Dict[str, Any]] = None | ||
userNotFound: Optional[bool] = None | ||
|
||
|
||
class CognitoPreAuthenticationTriggerModel(CognitoTriggerBaseSchema): | ||
triggerSource: Literal["PreAuthentication_Authentication"] | ||
request: CognitoPreAuthenticationRequestModel | ||
response: Dict[str, Any] = {} | ||
|
||
|
||
# Models for Post-Authentication flow | ||
class CognitoPostAuthenticationRequestModel(BaseModel): | ||
userAttributes: Dict[str, Any] | ||
newDeviceUsed: Optional[bool] = None | ||
clientMetadata: Optional[Dict[str, Any]] = None | ||
|
||
|
||
class CognitoPostAuthenticationTriggerModel(CognitoTriggerBaseSchema): | ||
triggerSource: Literal["PostAuthentication_Authentication"] | ||
request: CognitoPostAuthenticationRequestModel | ||
response: Dict[str, Any] = {} | ||
|
||
|
||
# Models for Pre-Token Generation flow | ||
class CognitoGroupConfigurationModel(BaseModel): | ||
groupsToOverride: List[str] | ||
iamRolesToOverride: List[str] | ||
preferredRole: Optional[str] = None | ||
|
||
|
||
class CognitoPreTokenGenerationRequestModel(BaseModel): | ||
userAttributes: Dict[str, Any] | ||
groupConfiguration: CognitoGroupConfigurationModel | ||
clientMetadata: Optional[Dict[str, Any]] = None | ||
|
||
|
||
class CognitoPreTokenGenerationTriggerModelV1(CognitoTriggerBaseSchema): | ||
triggerSource: str | ||
request: CognitoPreTokenGenerationRequestModel | ||
response: Dict[str, Any] = {} | ||
|
||
|
||
class CognitoPreTokenGenerationRequestModelV2AndV3(CognitoPreTokenGenerationRequestModel): | ||
scopes: Optional[Dict[str, Any]] = None | ||
|
||
|
||
class CognitoPreTokenGenerationTriggerModelV2AndV3(CognitoTriggerBaseSchema): | ||
request: CognitoPreTokenGenerationRequestModelV2AndV3 | ||
response: Dict[str, Any] = {} | ||
|
||
|
||
# Models for User Migration flow | ||
class CognitoMigrateUserRequestModel(BaseModel): | ||
password: str | ||
validationData: Optional[Dict[str, Any]] = None | ||
clientMetadata: Optional[Dict[str, Any]] = None | ||
|
||
|
||
class CognitoMigrateUserResponseModel(BaseModel): | ||
userAttributes: Optional[Dict[str, Any]] = None | ||
finalUserStatus: Optional[str] = None | ||
messageAction: Optional[str] = None | ||
desiredDeliveryMediums: Optional[List[str]] = None | ||
forceAliasCreation: Optional[bool] = None | ||
enableSMSMFA: Optional[bool] = None | ||
|
||
|
||
class CognitoMigrateUserTriggerModel(CognitoTriggerBaseSchema): | ||
triggerSource: str | ||
userName: str | ||
request: CognitoMigrateUserRequestModel | ||
response: CognitoMigrateUserResponseModel | ||
|
||
|
||
# Models for Custom Message flow | ||
class CognitoCustomMessageRequestModel(BaseModel): | ||
userAttributes: Dict[str, Any] | ||
codeParameter: str | ||
linkParameter: Optional[str] = None | ||
usernameParameter: Optional[str] = None | ||
clientMetadata: Optional[Dict[str, Any]] = None | ||
|
||
|
||
class CognitoCustomMessageResponseModel(BaseModel): | ||
smsMessage: Optional[str] = None | ||
emailMessage: Optional[str] = None | ||
emailSubject: Optional[str] = None | ||
|
||
|
||
class CognitoCustomMessageTriggerModel(CognitoTriggerBaseSchema): | ||
triggerSource: str | ||
request: CognitoCustomMessageRequestModel | ||
response: CognitoCustomMessageResponseModel | ||
|
||
|
||
# Models for Custom Email/SMS Sender flow | ||
class CognitoCustomEmailSMSSenderRequestModel(BaseModel): | ||
type: str | ||
code: str | ||
clientMetadata: Optional[Dict[str, Any]] = None | ||
userAttributes: Dict[str, Any] | ||
|
||
|
||
class CognitoCustomEmailSenderTriggerModel(CognitoTriggerBaseSchema): | ||
triggerSource: Literal["CustomEmailSender_SignUp"] | ||
request: CognitoCustomEmailSMSSenderRequestModel | ||
|
||
|
||
class CognitoCustomSMSSenderTriggerModel(CognitoTriggerBaseSchema): | ||
triggerSource: Literal["CustomSMSSender_SignUp"] | ||
request: CognitoCustomEmailSMSSenderRequestModel | ||
|
||
|
||
# Models for Challenge Authentication flows | ||
class CognitoChallengeResultModel(BaseModel): | ||
challengeName: Literal[ | ||
"SRP_A", | ||
"PASSWORD_VERIFIER", | ||
"SMS_MFA", | ||
"EMAIL_OTP", | ||
"SOFTWARE_TOKEN_MFA", | ||
"DEVICE_SRP_AUTH", | ||
"DEVICE_PASSWORD_VERIFIER", | ||
"ADMIN_NO_SRP_AUTH", | ||
] | ||
challengeResult: bool | ||
challengeMetadata: Optional[str] = None | ||
|
||
|
||
class CognitoAuthChallengeRequestModel(BaseModel): | ||
userAttributes: Dict[str, Any] | ||
session: List[CognitoChallengeResultModel] | ||
clientMetadata: Optional[Dict[str, Any]] = None | ||
userNotFound: Optional[bool] = None | ||
|
||
|
||
class CognitoDefineAuthChallengeResponseModel(BaseModel): | ||
challengeName: Optional[str] = None | ||
issueTokens: Optional[bool] = None | ||
failAuthentication: Optional[bool] = None | ||
|
||
|
||
class CognitoDefineAuthChallengeTriggerModel(CognitoTriggerBaseSchema): | ||
triggerSource: Literal["DefineAuthChallenge_Authentication"] | ||
request: CognitoAuthChallengeRequestModel | ||
response: CognitoDefineAuthChallengeResponseModel | ||
|
||
|
||
class CognitoCreateAuthChallengeResponseModel(BaseModel): | ||
publicChallengeParameters: Optional[Dict[str, Any]] = None | ||
privateChallengeParameters: Optional[Dict[str, Any]] = None | ||
challengeMetadata: Optional[str] = None | ||
|
||
|
||
class CognitoCreateAuthChallengeTriggerModel(CognitoTriggerBaseSchema): | ||
triggerSource: Literal["CreateAuthChallenge_Authentication"] | ||
request: CognitoAuthChallengeRequestModel | ||
response: CognitoCreateAuthChallengeResponseModel | ||
|
||
|
||
class CognitoVerifyAuthChallengeRequestModel(BaseModel): | ||
userAttributes: Dict[str, Any] | ||
privateChallengeParameters: Dict[str, Any] | ||
challengeAnswer: str | ||
clientMetadata: Optional[Dict[str, Any]] = None | ||
userNotFound: Optional[bool] = None | ||
|
||
|
||
class CognitoVerifyAuthChallengeResponseModel(BaseModel): | ||
answerCorrect: bool | ||
|
||
|
||
class CognitoVerifyAuthChallengeTriggerModel(CognitoTriggerBaseSchema): | ||
triggerSource: Literal["VerifyAuthChallengeResponse_Authentication"] | ||
request: CognitoVerifyAuthChallengeRequestModel | ||
response: CognitoVerifyAuthChallengeResponseModel |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.