Skip to content

Commit

Permalink
#69 [feat] : 토큰 유효 검증을 추가한다
Browse files Browse the repository at this point in the history
  • Loading branch information
bbbang105 committed Oct 5, 2024
1 parent 9bcba4f commit 31d6992
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/side/onetime/util/JwtUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public String getTokenFromHeader(String authorizationHeader) {
// 토큰에서 유저 id를 반환하는 메서드
public Long getUserIdFromToken(String token) {
try {
validateTokenExpiration(token);
String userId = Jwts.parser()
.verifyWith(this.getSigningKey())
.build()
Expand All @@ -96,6 +97,7 @@ public Long getUserIdFromToken(String token) {
// 헤더에서 유저를 반환하는 메서드
public User getUserFromHeader(String authorizationHeader) {
String token = getTokenFromHeader(authorizationHeader);
validateTokenExpiration(token);

return userRepository.findById(getUserIdFromToken(token))
.orElseThrow(() -> new UserException(UserErrorResult._NOT_FOUND_USER));
Expand All @@ -104,6 +106,7 @@ public User getUserFromHeader(String authorizationHeader) {
// 토큰에서 provider를 반환하는 메서드
public String getProviderFromToken(String token) {
try {
validateTokenExpiration(token);
String userId = Jwts.parser()
.verifyWith(this.getSigningKey())
.build()
Expand All @@ -122,6 +125,7 @@ public String getProviderFromToken(String token) {
// 토큰에서 providerId를 반환하는 메서드
public String getProviderIdFromToken(String token) {
try {
validateTokenExpiration(token);
String providerId = Jwts.parser()
.verifyWith(this.getSigningKey())
.build()
Expand All @@ -140,6 +144,7 @@ public String getProviderIdFromToken(String token) {
// 토큰에서 이름을 반환하는 메서드
public String getNameFromToken(String token) {
try {
validateTokenExpiration(token);
String name = Jwts.parser()
.verifyWith(this.getSigningKey())
.build()
Expand All @@ -158,6 +163,7 @@ public String getNameFromToken(String token) {
// 토큰에서 이메일을 반환하는 메서드
public String getEmailFromToken(String token) {
try {
validateTokenExpiration(token);
String email = Jwts.parser()
.verifyWith(this.getSigningKey())
.build()
Expand Down

0 comments on commit 31d6992

Please sign in to comment.