From 650223c63b3aaaf1ba479170058594bc7c306d79 Mon Sep 17 00:00:00 2001 From: Jinseong Date: Mon, 6 Jan 2025 22:58:15 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=ED=86=A0=ED=81=B0=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?,=20=EA=B2=80=EC=A6=9D,=20=EC=A1=B0=ED=9A=8C=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - JWT 생성 구현 - Claims(Payload), 검증, 조회 미구현 resolve : #27 --- .../global/jwt/provider/JwtProvider.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/main/java/univ/goormthon/kongju/global/jwt/provider/JwtProvider.java diff --git a/src/main/java/univ/goormthon/kongju/global/jwt/provider/JwtProvider.java b/src/main/java/univ/goormthon/kongju/global/jwt/provider/JwtProvider.java new file mode 100644 index 0000000..358f3e0 --- /dev/null +++ b/src/main/java/univ/goormthon/kongju/global/jwt/provider/JwtProvider.java @@ -0,0 +1,38 @@ +package univ.goormthon.kongju.global.jwt.provider; + +import io.jsonwebtoken.Claims; +import io.jsonwebtoken.Jwts; +import org.springframework.security.core.Authentication; +import org.springframework.stereotype.Component; + +import javax.crypto.SecretKey; +import java.util.Date; + +@Component +public class JwtProvider { + + private final SecretKey key = Jwts.SIG.HS256.key().build(); + private final long validityInMilliseconds = 1000 * 60 * 60; // 1시간 + + public String generateToken(Authentication authentication) { + String email = authentication.getName(); + + return Jwts.builder() + .subject(email) + .signWith(key) + .issuedAt(new Date()) + .expiration(new Date(new Date().getTime() + validityInMilliseconds)) + .compact(); + } + + public Claims getClaims(String token) { + } + + public boolean validateToken(String token) { + } + + public Authentication getAuthentication(String token) { + } + + +}