afpi: Ensure Dart expiresAt
uses the UTC time zone
#331
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.
📋 Changes
Currently, both native implementations (iOS and Android) provide credentials to the Dart layer that include an
expiresAt
value formatted as ISO 8601 date with UTC time zone. More specifically, the format used follows the RFC 3339's profile of ISO 8601 dates, which is somewhat more restrictive for the sake of simplicity:Among the fields that the RFC 3339 deems mandatory (that ISO 8601 does not) is the time zone. So, a RFC 3339 date must contain time zone information to be valid. The native implementations, in particular, use UTC as the time zone.
Besides passing RFC 3339
expiresAt
dates to the Dart layer, the native implementations expect that anyexpiresAt
dates received from the Dart layer also to be RFC 3339 dates. But, here comes the problem: the Dart layer generates the date strings from a DateTime object. ADateTime
can either be set as "local" time, or can be set as UTC. That is, DartDateTime
objects do not support time zones other than UTC and "local". And by default, they'll be set as "local", meaning that when formatted as ISO 8601 dates, they won't be RFC 3339 compliant:We were not setting the
expiresAt
dates as UTC on the Dart layer. But still, this did not cause issues in most cases, because the Dart layer was dealing withexpiresAt
dates coming from the native implementations. As mentioned before, those are RFC 3339 compliant, and thus contain time zone information –theZ
that signals UTC. It only caused issues when dealing withDateTime
objects created externally, that were not set as UTC –e.g. as described in #304To fix this issue, this PR enforces UTC for all
expiresAt
dates either coming from the native layer or going to the native layer, in the Dart layer.📎 References
Fixes #304
See also https://ijmacd.github.io/rfc3339-iso8601/
🎯 Testing
Unit tests were added. The fix was also tested manually on both Android and iOS.