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 overloads to setExpiration and setIssuedAt #801

Closed
Aleksander-Dorkov opened this issue Aug 24, 2023 · 1 comment
Closed

Add overloads to setExpiration and setIssuedAt #801

Aleksander-Dorkov opened this issue Aug 24, 2023 · 1 comment

Comments

@Aleksander-Dorkov
Copy link

Aleksander-Dorkov commented Aug 24, 2023

Hello, do you have the time to add overloads to the methods setExpiration and setIssuedAt of Jwts.builder() that accept LocalDateTime instead of the Date class, witch was kind of deprecated (not rly, but almost) 10 years go.

        Instant now = Instant.now();
        JwtBuilder jwtBuilder = Jwts.builder()
                .setId(UUID.randomUUID().toString())
                .setSubject(userDetails.getId().toString())
                .claim("username", userDetails.getUsername())
                .claim("authorities", authorities)
                .setIssuedAt(Date.from(now))
                .setExpiration(Date.from(now.plus(1, ChronoUnit.DAYS)))
                .signWith(KEY);

Instead of the code above can we have

        JwtBuilder jwtBuilder = Jwts.builder()
                .setId(UUID.randomUUID().toString())
                .setSubject(userDetails.getId().toString())
                .claim("username", userDetails.getUsername())
                .claim("authorities", authorities)
                .setIssuedAt(LocalDateTime.now())
                .setExpiration(LocalDateTime.now().plus(1, ChronoUnit.DAYS))
                .signWith(KEY);

It should be fairly simple, because you just convert them to a unix timestamp, if I am not mistaking.

@lhazlewood
Copy link
Contributor

Closing as duplicate of #662

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants