calavera / aws-lambda-events

Rust event types for AWS Lambda
MIT License
128 stars 55 forks source link

Cognito passes in explicitly null booleans for DefineAuth responses #158

Closed djrenren closed 1 year ago

djrenren commented 1 year ago

Another fun cognito issue cuz this service is wack sometimes:

When cognito passes in the response field of CognitoEventUserPoolsDefineAuthChallenge, it can look like so:

{
   "challengeName": null,
   "failAuthentication": null,
   "issueTokens": null
}

But the definition of CognitoEventUserPoolsDefineAuthResponse is:

https://github.com/calavera/aws-lambda-events/blob/9b0c65902902380c59ac267b48d502f51246c915/src/cognito/mod.rs#L308-L317

Serde does not use the default implementation if a value is explicitly set to null. It only uses default if the value is excluded. This results in a failure to deserialize. I'm currently working around this by using my own type defined with:

#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DefineAuthResponse{
    #[serde(default)]
    pub challenge_name: Option<String>,
    #[serde(default)]
    pub issue_tokens: Option<bool>,
    #[serde(default)]
    pub fail_authentication: Option<bool>,
}

But I'm not sure how Cognito handles the null values on the output. It may require them to be booleans.

calavera commented 1 year ago

But I'm not sure how Cognito handles the null values on the output. It may require them to be booleans.

No idea either. Feel free to open a PR with suggested changes.