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

Use java.time.Instant instead of java.text.SimpleDateFormat #469

Merged
merged 3 commits into from
Oct 9, 2024

Conversation

gferon
Copy link
Contributor

@gferon gferon commented Jul 23, 2024

📋 Changes

After spending quite some time trying to understand why our access tokens would not be refreshed, I realized that something was wrong with the expiresAt field. The issue affects (at least) Android because the UTC timezone is added in the format while the formatter itself is timezone-unaware.

With the following added print statements, you can observe that the Credentials.expiresAt is formatted from local time with an appended Z, which means we lose the timezone information.

I/System.out(18918): RenewApiRequestHandler::onSuccess credentials.expiresAt Tue Jul 23 08:49:05 GMT+02:00 2024
I/System.out(18918): RenewApiRequestHandler::onSuccess formattedDate 2024-07-23T08:49:05.555Z

Making sure all SimpleDateFormat are set to the UTC timezone fixes the issue, but since java.util.Date is notably confusing to work with, a better fix is to switch to java.time.Instant and use Instant.toString() as well as Instant.parse() which work with ISO-8601 formatting.

🎯 Testing

Making sure the tests still use SimpleDateFormat is a great way to avoid having the actual implementation have the same bug than the tests. Unit tests should be good enough in that case.

@gferon gferon requested a review from a team as a code owner July 23, 2024 07:54
@gferon gferon requested a review from a team as a code owner September 9, 2024 11:52
@gferon
Copy link
Contributor Author

gferon commented Sep 9, 2024

Could anybody in the team review #469 or #468 depending on the preferred change? We're running a patched version of auth0_flutter and I would be happy if this fix could be merged.

Copy link
Contributor

@pmathew92 pmathew92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove all println statements from the codebase

@pmathew92
Copy link
Contributor

@gferon Thank you for raising this PR . the team will have a look into this

@gferon
Copy link
Contributor Author

gferon commented Sep 9, 2024

Please remove all println statements from the codebase

Sure, I mostly wanted to first know which approach you favor.

EDIT: done.

Copy link
Contributor

@desusai7 desusai7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @gferon

Thank you for raising the PR, I've reviewed it and it looks good to me, Can you remove the println statements and also update the tests accordingly ?

auth0_flutter_platform_interface/lib/src/credentials.dart Outdated Show resolved Hide resolved
@desusai7
Copy link
Contributor

@gferon, thanks a lot for addressing the comment, can you please update the unit tests as well to use java.time.Instant ?

@gferon
Copy link
Contributor Author

gferon commented Sep 19, 2024

@gferon, thanks a lot for addressing the comment, can you please update the unit tests as well to use java.time.Instant ?

I updated the PR description. I think it's actually good to keep the old way of doing it in the tests, to avoid testing a bug itself (which was happening before).

@gferon
Copy link
Contributor Author

gferon commented Oct 1, 2024

Hi @pmathew92 could you maybe at least approve the workflow runs so I can fix any CI issues before we move forward? The bug is still out there and it's not a nice one.

@pmathew92
Copy link
Contributor

@gferon Apologies . I have approved the workflow runs. Looks like the merge is blocked due to not being signed commits.Could you please sign your commits

@tikal
Copy link

tikal commented Oct 8, 2024

Hi, any update on this?

@gferon
Copy link
Contributor Author

gferon commented Oct 8, 2024

Could you please sign your commits

@pmathew92 I have signed my commits, not sure why it's a requirement in the first place.

@gferon gferon requested a review from pmathew92 October 8, 2024 20:27
@desusai7 desusai7 merged commit 66ad9ff into auth0:main Oct 9, 2024
7 of 8 checks passed
@pmathew92
Copy link
Contributor

@gferon We have merged the PR . Thank you for your contributions

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 this pull request may close these issues.

Credentials seem to return wrong expire date Credentials on Android have incorrect expiresAt value
4 participants