X Tutup
Skip to content

Updated date time APIs#392

Merged
jimmyjames merged 11 commits intoauth0:4.0.0-DEVfrom
jimmyjames:updated-date-time-apis
Mar 5, 2020
Merged

Updated date time APIs#392
jimmyjames merged 11 commits intoauth0:4.0.0-DEVfrom
jimmyjames:updated-date-time-apis

Conversation

@jimmyjames
Copy link
Copy Markdown
Contributor

@jimmyjames jimmyjames commented Feb 14, 2020

Changes

Adds new APIs for DateTime claims using java.time.Instant

Motivations:

  • JDK8 introduced new Date/time classes to address issues with the legacy Date functionality. Over time developers have transitioned to the new APIs.
  • Some of the improvements of Instant over date are immutability (thread-safe), better API design allowing for more natural time-based calculations, and nanosecond precision (as opposed to millisecond precision with java.util.Date).

This change adds the following new public APIs:

Claim.java:

  • Instant asInstant()

Clock.java:

  • Instant getNow()

JWTCreator.java:

  • Builder withNotBefore(Instant notBefore)
  • Builder withIssuedAt(Instant issuedAt)
  • Builder withClaim(String name, Instant value)

Payload.java:

Note that these methods are all post-fixed with Instant. This is to allow both the existing java.util.Date APIs to exist alongside the new APIs.

  • Instant getExpiresAtInstant()
  • Instant getNotBeforeInstant()
  • Instant getIssuedAtInstant()

Verification.java:

  • Verification withClaim(String name, Instant value)

A separate later PR will deprecate the java.util.Date APIs in favor of these new ones.

References

There are many articles and resources regarding the new date/time APIs introduced in JDK8. This article discusses it at a high level.

Testing

Tests updated to use the new Date/Time APIs.

Checklist

@jimmyjames jimmyjames added CH: Breaking Change large This PR may require significant effort to action, or contains many changes to review labels Feb 14, 2020
@jimmyjames jimmyjames added this to the v4-Next milestone Feb 14, 2020
@jimmyjames jimmyjames requested review from a team and lbalmaceda February 14, 2020 04:00
@stevehobbsdev
Copy link
Copy Markdown

stevehobbsdev commented Feb 14, 2020

@jimmyjames As someone reviewing this, it would be beneficial here to have some information in the PR about why these changes are being made. What are the benefits of Instant over Date?

@jimmyjames
Copy link
Copy Markdown
Contributor Author

@jimmyjames As someone reviewing this, it would be beneficial here to have some information in the PR about why these changes are being made. What are the benefits of Instant over Date?

I've updated the PR description to capture the motivations.

@jimmyjames jimmyjames force-pushed the updated-date-time-apis branch from 69415a3 to 1dcc415 Compare March 4, 2020 22:24
@jimmyjames jimmyjames requested a review from lbalmaceda March 4, 2020 22:26
@jimmyjames jimmyjames merged commit 6210713 into auth0:4.0.0-DEV Mar 5, 2020
/**
* The Clock class is used to wrap calls to Date class.
*/
public interface Clock {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

... probably not appropriate to do it during this PR, but should this interface be deprecated in favor of java.time.Clock?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CH: Added large This PR may require significant effort to action, or contains many changes to review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

X Tutup