Skip to content

Commit

Permalink
refactor: claim key 상수화, test yml에 jwt 설정 추가 (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
medoeun committed Aug 26, 2024
1 parent b848cb5 commit 85b7ff6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
@Slf4j
@Component
public class JwtUtil {
private static final String CLAIM_MEMBER_ID = "memberId";
private static final String CLAIM_ACCOUNT = "account";

private final Key secretKey;

Expand All @@ -42,8 +44,8 @@ public String generateToken(Authentication authentication) {

// JWT 토큰에 포함되는 정보(페이로드): jwt의 주체 memberId로
Claims claims = Jwts.claims().setSubject(String.valueOf(memberId));
claims.put("memberId", memberId);
claims.put("account", account);
claims.put(CLAIM_MEMBER_ID, memberId);
claims.put(CLAIM_ACCOUNT, account);

Date now = new Date();
Date validity = new Date(now.getTime() + tokenValidityInseconds * 1000);
Expand Down Expand Up @@ -91,7 +93,7 @@ public String getAccount(String token) {
.build()
.parseClaimsJws(token)
.getBody()
.get("account", String.class);
.get(CLAIM_ACCOUNT, String.class);
}

// JWT 토큰 유효성 검증
Expand Down
32 changes: 0 additions & 32 deletions src/test/resources/application-test.yml

This file was deleted.

14 changes: 14 additions & 0 deletions src/test/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
spring:
datasource:
url: jdbc:h2:mem:testdb;MODE=PostgreSQL
username: sa
driver-class-name: org.h2.Driver

jpa:
show-sql: true
hibernate:
ddl-auto: create-drop

jwt:
secret: dGVzdC1zZWNyZXQta2V5
token-validity-in-seconds: 3600

0 comments on commit 85b7ff6

Please sign in to comment.