Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[deploy] merge to main #90

Merged
merged 2 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ public class JwtTokenProvider {
private long REFRESH_TOKEN_EXPIRE_TIME;

private static final String MEMBER_ID = "memberId";
private SecretKey secretKey;

@PostConstruct
protected void init() {
byte[] keyBytes = Base64.getEncoder().encode(JWT_SECRET.getBytes(StandardCharsets.UTF_8));
this.secretKey = Keys.hmacShaKeyFor(keyBytes);
JWT_SECRET = Base64.getEncoder().encodeToString(JWT_SECRET.getBytes(StandardCharsets.UTF_8));
}

public String issueAccessToken(final Authentication authentication) {
Expand All @@ -54,10 +52,15 @@ private String issueToken(final Authentication authentication, final long expire
return Jwts.builder()
.setHeaderParam(Header.TYPE, Header.JWT_TYPE)
.setClaims(claims)
.signWith(secretKey)
.signWith(getSigningKey())
.compact();
}

private SecretKey getSigningKey() {
String encodedKey = Base64.getEncoder().encodeToString(JWT_SECRET.getBytes()); //SecretKey 통해 서명 생성
return Keys.hmacShaKeyFor(encodedKey.getBytes()); //일반적으로 HMAC (Hash-based Message Authentication Code) 알고리즘 사용
}

public JwtValidationType validateToken(String token) {
try {
Claims claims = getBody(token);
Expand All @@ -76,7 +79,7 @@ public JwtValidationType validateToken(String token) {

private Claims getBody(final String token) {
return Jwts.parserBuilder()
.setSigningKey(secretKey)
.setSigningKey(getSigningKey())
.build()
.parseClaimsJws(token)
.getBody();
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ spring:

jpa:
hibernate:
ddl-auto: create
ddl-auto: update
show-sql: true
properties:
hibernate:
Expand All @@ -23,7 +23,7 @@ spring:

data:
redis:
host: localhost
host: ${DEV_REDIS_HOST}
port: 6379

security:
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ spring:
password: ${PROD_DB_PASSWORD}
jpa:
hibernate:
ddl-auto: create
show-sql: false
ddl-auto: update
show-sql: true
properties:
hibernate:
dialect: org.hibernate.dialect.MySQLDialect
format_sql: true

data:
redis:
host: localhost
host: ${PROD_REDIS_HOST}
port: 6379

security:
Expand Down
Loading