Skip to content

Commit

Permalink
#323 ✨ feat: Refresh Token의 페이로드로부터 이메일 정보 파싱
Browse files Browse the repository at this point in the history
  • Loading branch information
yujung-Jang committed Dec 22, 2022
1 parent 7f4e742 commit cbb639d
Showing 1 changed file with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -113,6 +113,23 @@ public Long parseMemberId(String jwt) {
return claims.get("memberId", Long.class);
}

public String parseEmailFromPayload(String jwt) {

HashMap<String, String> 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);
Expand Down

0 comments on commit cbb639d

Please sign in to comment.