jjwt
jjwt copied to clipboard
Add a convenience expiration setter which takes a duration
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)));
Good idea! I think expireAfter might be a bit more readable, e.g.:
expireAfter(15, TimeUnit.MINUTES)
Thoughts?
yep, that does make for a more fluent api.
Is there any ETA when is this feature going to be available?
Thanks!
Pull requests (with tests! we enforce 100% code coverage) are welcome!
Moving this to 1.0.0 in favor of using the JDK8+ java.time.duration