diff --git a/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/TokenResolver.java b/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/TokenResolver.java index c69818d..d0df2cb 100644 --- a/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/TokenResolver.java +++ b/simple-jwt-facade/src/main/java/cn/org/codecrafters/simplejwt/TokenResolver.java @@ -110,6 +110,26 @@ public interface TokenResolver { */ T extract(String token, Class targetType); + /** + * Re-generate a new token with the payload in the old one. + * + * @param oldToken the old token + * @param expireAfter how long the new token can be valid for + * @return re-generated token with the payload in the old one + */ + String renew(String oldToken, Duration expireAfter); + + /** + * Re-generate a new token with the payload in the old one. + * + * @param oldToken the old token + * @return re-generated token with the payload in the old one + * @see #renew(String, Duration) + */ + default String renew(String oldToken) { + return renew(oldToken, Duration.ofMinutes(30)); + } + /** * Renews the given expired token with the specified custom payload data. * @@ -129,7 +149,9 @@ public interface TokenResolver { * token * @return the renewed token as a {@code String} */ - String renew(String oldToken, Map payload); + default String renew(String oldToken, Map payload) { + return renew(oldToken, Duration.ofMinutes(30), payload); + } /** * Renews the given expired token with the specified strongly-typed @@ -156,6 +178,8 @@ public interface TokenResolver { * renewed token * @return the renewed token as a {@code String} */ - String renew(String oldToken, T payload); + default String renew(String oldToken, T payload) { + return renew(oldToken, Duration.ofMinutes(30), payload); + } }