From cbb639d3cf3dc9f414cb48e9065287e66722d77a Mon Sep 17 00:00:00 2001 From: yujung-Jang Date: Thu, 22 Dec 2022 09:25:39 +0900 Subject: [PATCH] =?UTF-8?q?#323=20:sparkles:=20feat:=20Refresh=20Token?= =?UTF-8?q?=EC=9D=98=20=ED=8E=98=EC=9D=B4=EB=A1=9C=EB=93=9C=EB=A1=9C?= =?UTF-8?q?=EB=B6=80=ED=84=B0=20=EC=9D=B4=EB=A9=94=EC=9D=BC=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=ED=8C=8C=EC=8B=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/security/jwt/JwtTokenizer.java | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/com/ilchinjo/mainproject/global/security/jwt/JwtTokenizer.java b/server/src/main/java/com/ilchinjo/mainproject/global/security/jwt/JwtTokenizer.java index 19618076..39049231 100644 --- a/server/src/main/java/com/ilchinjo/mainproject/global/security/jwt/JwtTokenizer.java +++ b/server/src/main/java/com/ilchinjo/mainproject/global/security/jwt/JwtTokenizer.java @@ -1,5 +1,7 @@ package com.ilchinjo.mainproject.global.security.jwt; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import com.ilchinjo.mainproject.global.security.userdetails.MemberDetailsService; import io.jsonwebtoken.*; import io.jsonwebtoken.io.Decoders; @@ -16,9 +18,7 @@ import java.nio.charset.StandardCharsets; import java.security.Key; -import java.util.Calendar; -import java.util.Date; -import java.util.Map; +import java.util.*; @Slf4j @Component @@ -113,6 +113,23 @@ public Long parseMemberId(String jwt) { return claims.get("memberId", Long.class); } + public String parseEmailFromPayload(String jwt) { + + HashMap payloadMap; + + try { + String[] splitJwt = jwt.split("\\."); + String payload = new String(Base64.getDecoder().decode(splitJwt[1].getBytes())); + + payloadMap = new ObjectMapper().readValue(payload, HashMap.class); + } catch (JsonProcessingException e) { + log.error(e.getMessage()); + return null; + } + + return String.valueOf(payloadMap.get("sub")); + } + public JwtStatus validateToken(String token) { String base64EncodedSecretKey = encodeBase64SecretKey(secretKey);