jjwt icon indicating copy to clipboard operation
jjwt copied to clipboard

Add a convenience expiration setter which takes a duration

Open jahlborn opened this issue 10 years ago • 5 comments

I would imagine that when most people are setting an expiration on a JWT, they will be using some configured timeout duration (e.g. 15 minutes). the ClaimsMutator has a basic setExpiration helper which takes the expiration date. It would be great if you added a convenience method which took the duration and did the math to compute the final exipration date, something like:

public T setExpirationAfter(long duration, TimeUnit timeUnit);

Where the impl is something like:

return setExpiration(new Date(System.currentTimeMillis() + timeUnit.toMillis(duration)));

jahlborn avatar Oct 15 '15 01:10 jahlborn

Good idea! I think expireAfter might be a bit more readable, e.g.:

expireAfter(15, TimeUnit.MINUTES)

Thoughts?

lhazlewood avatar Oct 15 '15 01:10 lhazlewood

yep, that does make for a more fluent api.

jahlborn avatar Oct 15 '15 02:10 jahlborn

Is there any ETA when is this feature going to be available?

Thanks!

adcoolguy avatar Jan 09 '16 22:01 adcoolguy

Pull requests (with tests! we enforce 100% code coverage) are welcome!

lhazlewood avatar Sep 11 '16 21:09 lhazlewood

Moving this to 1.0.0 in favor of using the JDK8+ java.time.duration

lhazlewood avatar Jul 20 '18 20:07 lhazlewood