Skip to content
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

Unable to parse updated_at timestamp from Auth0 #23

Closed
phated opened this issue Jun 18, 2020 · 4 comments · Fixed by #55
Closed

Unable to parse updated_at timestamp from Auth0 #23

phated opened this issue Jun 18, 2020 · 4 comments · Fixed by #55

Comments

@phated
Copy link

phated commented Jun 18, 2020

I'm working on integrating this library with Auth0 and ran into an issue where the format of their updated_at field fails to parse. Their format is "2020-06-16T03:23:10.426Z".

I changed this type to String in the claims.rs and it parses successfully.

@ramosbugs
Copy link
Owner

looks like @auth0 isn't following the OIDC spec:

Time the End-User's information was last updated. Its value is a JSON number representing the number of seconds from 1970-01-01T0:0:0Z as measured in UTC until the date/time.

somehow they're a certified OIDC implementation but haven't bothered to follow the spec here, making their product incompatible with strongly-typed clients that do adhere to the spec.

that said, I would accept a PR that makes the serde parser also accept ISO 8601 date/time strings behind a non-default feature flag. the updated_at method should continue to return Option<DateTime<Utc>> though.

@phated
Copy link
Author

phated commented Jun 19, 2020

I tried looking into this and the macros leave me complete stumped on trying to PR what you are asking for ☹️

@ramosbugs
Copy link
Owner

it's probably easiest to add the logic here:

Option(DateTime(Seconds($field:ident)))) => {
if $field.is_some() {
return Err(serde::de::Error::duplicate_field(stringify!($field)));
} else if let Some(language_tag) = $language_tag_opt {
return Err(
serde::de::Error::custom(
format!(
concat!("unexpected language tag `{}` for key `", stringify!($field), "`"),
language_tag.as_ref()
)
)
);
}
let seconds = $map.next_value::<Option<Seconds>>()?;
$field = seconds
.map(|sec| seconds_to_utc(&sec).map_err(|_| serde::de::Error::custom(
format!(
concat!(
"failed to parse `{}` as UTC datetime (in seconds) for key `",
stringify!($field),
"`"
),
*sec,
)
))).transpose()?;
};

@ramosbugs
Copy link
Owner

basically instead of $map.next_value::<Option<Seconds>> we probably need to replace Option<Seconds> with serde_json::Value or some other enum that accepts both strings and JSON numbers, and then accepts/parses the string representation only if the feature flag is enabled

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants