auth0 / auth0-flutter

Auth0 SDK for Flutter
https://pub.dev/documentation/auth0_flutter/latest/
Apache License 2.0
57 stars 37 forks source link

afpi: Ensure Dart `expiresAt` uses the UTC time zone #331

Closed Widcket closed 8 months ago

Widcket commented 8 months ago

📋 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:

Screenshot 2023-10-31 at 23 15 09

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 any expiresAt 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. A DateTime can either be set as "local" time, or can be set as UTC. That is, Dart DateTime 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:

Screenshot 2023-10-31 at 23 43 40

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 with expiresAt dates coming from the native implementations. As mentioned before, those are RFC 3339 compliant, and thus contain time zone information –the Z that signals UTC. It only caused issues when dealing with DateTime objects created externally, that were not set as UTC –e.g. as described in https://github.com/auth0/auth0-flutter/issues/304

To 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 https://github.com/auth0/auth0-flutter/issues/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.

codecov[bot] commented 8 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (253209a) 96.08% compared to head (7e08c9b) 95.79%. Report is 14 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #331 +/- ## ============================================ - Coverage 96.08% 95.79% -0.30% ============================================ Files 97 76 -21 Lines 1611 1118 -493 Branches 331 281 -50 ============================================ - Hits 1548 1071 -477 + Misses 49 46 -3 + Partials 14 1 -13 ``` | [Flag](https://app.codecov.io/gh/auth0/auth0-flutter/pull/331/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=auth0) | Coverage Δ | | |---|---|---| | [auth0_flutter](https://app.codecov.io/gh/auth0/auth0-flutter/pull/331/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=auth0) | `100.00% <ø> (ø)` | | | [auth0_flutter_android](https://app.codecov.io/gh/auth0/auth0-flutter/pull/331/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=auth0) | `?` | | | [auth0_flutter_ios](https://app.codecov.io/gh/auth0/auth0-flutter/pull/331/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=auth0) | `?` | | | [auth0_flutter_platform_interface](https://app.codecov.io/gh/auth0/auth0-flutter/pull/331/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=auth0) | `87.03% <100.00%> (ø)` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=auth0#carryforward-flags-in-the-pull-request-comment) to find out more. | [Files](https://app.codecov.io/gh/auth0/auth0-flutter/pull/331?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=auth0) | Coverage Δ | | |---|---|---| | [...lutter\_platform\_interface/lib/src/credentials.dart](https://app.codecov.io/gh/auth0/auth0-flutter/pull/331?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=auth0#diff-YXV0aDBfZmx1dHRlcl9wbGF0Zm9ybV9pbnRlcmZhY2UvbGliL3NyYy9jcmVkZW50aWFscy5kYXJ0) | `100.00% <100.00%> (ø)` | | ... and [23 files with indirect coverage changes](https://app.codecov.io/gh/auth0/auth0-flutter/pull/331/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=auth0)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.