Skip to content

Commit

Permalink
refactor: 액세스 토큰으로부터 Claims를 얻어오는 예외 처리 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
YongsHub committed Sep 25, 2023
1 parent b470a8a commit f6a3a6e
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package com.ssafy.ssafsound.domain.auth.service.token;

import com.ssafy.ssafsound.domain.auth.dto.AuthenticatedMember;
import com.ssafy.ssafsound.domain.auth.exception.AuthException;
import com.ssafy.ssafsound.domain.auth.exception.AuthErrorInfo;
import io.jsonwebtoken.*;
import com.ssafy.ssafsound.domain.auth.exception.AuthException;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.ExpiredJwtException;
import io.jsonwebtoken.Jws;
import io.jsonwebtoken.JwtException;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.security.Keys;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import io.jsonwebtoken.security.Keys;

import java.nio.charset.StandardCharsets;
import java.security.Key;
import java.util.Date;
Expand Down Expand Up @@ -78,7 +83,10 @@ public AuthenticatedMember getParsedClaimsByAccessToken(String accessToken) {
.getBody();
} catch (ExpiredJwtException e) {
throw new AuthException(AuthErrorInfo.AUTH_TOKEN_EXPIRED);
} catch (JwtException | IllegalArgumentException e) {
throw new AuthException(AuthErrorInfo.AUTH_TOKEN_INVALID);
}

Long memberId = claims.get("memberId", Long.class);
String memberRole = claims.get("memberRole", String.class);

Expand Down

0 comments on commit f6a3a6e

Please sign in to comment.