calavera / aws-lambda-events

Rust event types for AWS Lambda

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cognito passes in explicitly null booleans for DefineAuth responses

djrenren opened this issue · comments

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:

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

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.

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.