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

Add a convenience expiration setter which takes a duration #60

Open
jahlborn opened this issue Oct 15, 2015 · 5 comments · May be fixed by #883
Open

Add a convenience expiration setter which takes a duration #60

jahlborn opened this issue Oct 15, 2015 · 5 comments · May be fixed by #883
Labels
enhancement jdk8 Changes related to migrating to JDK8 API features
Milestone

Comments

@jahlborn
Copy link

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)));
@lhazlewood
Copy link
Contributor

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

expireAfter(15, TimeUnit.MINUTES)

Thoughts?

@jahlborn
Copy link
Author

yep, that does make for a more fluent api.

@adcoolguy
Copy link

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

Thanks!

@lhazlewood
Copy link
Contributor

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

@lhazlewood lhazlewood added this to the 0.10.0 milestone Jul 11, 2018
@lhazlewood
Copy link
Contributor

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

@lhazlewood lhazlewood modified the milestones: 0.10.0, 1.0 Jul 20, 2018
@lhazlewood lhazlewood added the jdk8 Changes related to migrating to JDK8 API features label Sep 30, 2019
pveeckhout added a commit to pveeckhout/jjwt that referenced this issue Dec 25, 2023
The `expireAfter` method, accepting duration and timeUnit parameters, has been added to the JwtBuilder interface. This method calculates the JWT expiration date as either the issue time plus the duration or the system current time plus the duration if an issuedAt time hasn't been set. Additional tests for this feature have been included in `DefaultJwtParserTest.groovy`.
pveeckhout added a commit to pveeckhout/jjwt that referenced this issue Dec 25, 2023
Two new tests have been added to DefaultJwtParserTest to validate JWT expiration behavior. The tests ensure that for the 'expireAfter()' method, duration must be more than 0 and timeUnit cannot be null. The error messages for these validation checks have also been modified for clarity.
@pveeckhout pveeckhout linked a pull request Dec 25, 2023 that will close this issue
pveeckhout added a commit to pveeckhout/jjwt that referenced this issue Jan 10, 2024
The token expiry calculation logic has been cleaned up and optimized in DefaultJwtBuilder. A previously used optional stream has been replaced with a more straightforward if-else structure, leading to ease of code maintenance and improved readability.
pveeckhout added a commit to pveeckhout/jjwt that referenced this issue Jan 10, 2024
A typographical error in the comments of the 'exp' function in JwtBuilder was corrected. The phrase "specified it if" was changed to "specified if it", making the comments clearer and easier to understand.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement jdk8 Changes related to migrating to JDK8 API features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants