-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from Seasoning-Today/cancel-refresh-token-rota…
…tion Refresh Token Rotation 적용 해지
- Loading branch information
Showing
5 changed files
with
24 additions
and
110 deletions.
There are no files selected for viewing
35 changes: 0 additions & 35 deletions
35
src/main/java/today/seasoning/seasoning/common/config/RedisConfig.java
This file was deleted.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
src/main/java/today/seasoning/seasoning/common/token/domain/TokenInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 3 additions & 42 deletions
45
src/main/java/today/seasoning/seasoning/common/token/service/RefreshTokenService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,23 @@ | ||
package today.seasoning.seasoning.common.token.service; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import today.seasoning.seasoning.common.token.domain.TokenProperties; | ||
import today.seasoning.seasoning.common.exception.CustomException; | ||
import today.seasoning.seasoning.common.token.domain.TokenInfo; | ||
import today.seasoning.seasoning.common.util.JwtUtil; | ||
import today.seasoning.seasoning.common.util.TsidUtil; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class RefreshTokenService { | ||
|
||
private final TokenProperties tokenProperties; | ||
private final RedisTemplate<String, String> redisTemplate; | ||
|
||
// 리프레시 토큰 저장 | ||
public void save(String refreshToken, long userId) { | ||
Long expirationTimeMillis = tokenProperties.getRefreshTokenExpirationTimeMillis(); | ||
|
||
redisTemplate.opsForValue() | ||
.set(refreshToken, TsidUtil.toString(userId), expirationTimeMillis, TimeUnit.MILLISECONDS); | ||
} | ||
|
||
// 리프레시 토큰을 통한 토큰 재발급 | ||
public TokenInfo refresh(String oldRefreshToken) { | ||
// 토큰 유효성 검증 | ||
validateToken(oldRefreshToken); | ||
|
||
// 토큰 보유 사용자 아이디 조회 | ||
String userId = findUserId(oldRefreshToken); | ||
|
||
// 토큰 재발급 | ||
TokenInfo tokenInfo = JwtUtil.refreshToken(TsidUtil.toLong(userId), oldRefreshToken); | ||
|
||
// 기존 리프레시 토큰 삭제 후 새로운 리프레시 토큰 저장 | ||
redisTemplate.delete(oldRefreshToken); | ||
redisTemplate.opsForValue().set(tokenInfo.getRefreshToken(), userId); | ||
|
||
return tokenInfo; | ||
} | ||
|
||
private void validateToken(String refreshToken) { | ||
// 리프레시 토큰을 통한 액세스 토큰 재발급 | ||
public TokenInfo refresh(String refreshToken) { | ||
if (!JwtUtil.validate(refreshToken)) { | ||
throw new CustomException(HttpStatus.UNAUTHORIZED, "Invalid Token"); | ||
} | ||
} | ||
|
||
private String findUserId(String refreshToken) { | ||
String userId = redisTemplate.opsForValue().get(refreshToken); | ||
if (userId == null) { | ||
throw new CustomException(HttpStatus.UNAUTHORIZED, "Invalid Token"); | ||
} | ||
return userId; | ||
return JwtUtil.refreshToken(refreshToken); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters