Change to use Instant instead of Date

Issue #258 new
Josh Cummings created an issue

Once Nimbus upgrades to Java 8, it would be helpful if JWTClaimsSet used Instant instead of Date. For example,

Instant issuedAt = claims.getIssueTime();

or

Instant issuedAt = claims.getIssuedAt();

I think that Instant is a better representation of a moment in time anyway in addition to being immutable.

Right now, we are using JWTClaimsSetTransformer to make the accommodation, so we certainly have a workaround. It would just be nice to not have to do that.

As an alternative, I'd also be happy with:

Instant issuedAt = claims.getInstantClaim(JWTClaimsSet.ISSUED_AT)

Comments (5)

  1. Vladimir Dzhuvinov

    Yep, that would be nice, but because of Android users we'll need to stay with Java 7 for now (see my comment in issue #259).

  2. Jose Martinez

    If this project every updates to use Instant, you should also have the ability to use a custom Clock in DefaultJWTClaimsVerifier in order to get an instance of now. For instance, instead of doing now = new Date() it would be preferable to do now = clock.instant() .

    This would allow for easier testing of our application code because we can use our own Clock which would testing of time based claims more reproducible.

  3. Vladimir Dzhuvinov

    @Jose I suppose it’s possible to use a custom clock with the current java.util.Date arrangement. Feel free to submit a PR if you feel like exploring this.

  4. Log in to comment