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

token 관련 spring security 설정 수정 #184

Merged
merged 3 commits into from
Feb 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 @@ -45,6 +45,13 @@ public CommonResponse<MemberResponse.TestTokenDTO> testGenerateToken() {

@Operation(summary = "02-01 Member\uD83D\uDC64 소셜 로그인 V1", description = "구글, 애플 소셜로그인 API입니다.")
@PostMapping("/members/auth/{socialType}")
@ApiResponses({
@ApiResponse(responseCode = "1000", description = "OK, 성공"),
@ApiResponse(
responseCode = "COMMON001",
description = "request body에 담길 값이 이상함, result를 확인해주세요!",
content = @Content(schema = @Schema(implementation = CommonResponse.class))),
})
public CommonResponse<MemberResponse.LoginDTO> login(
@Parameter(description = "소셜로그인 종류", example = "google") @PathVariable
final SocialType socialType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public RefreshToken generateRefreshToken(String socialId, SocialType socialType)

LocalDateTime currentTime = LocalDateTime.now();

LocalDateTime expireTime = currentTime.plus(1000, ChronoUnit.MINUTES);
LocalDateTime expireTime = currentTime.plus(90, ChronoUnit.SECONDS);

return refreshTokenRepository.save(
RefreshToken.builder()
Expand All @@ -68,8 +68,6 @@ public RefreshToken reGenerateRefreshToken(MemberRequest.ReissueDTO request) {
() -> new RefreshTokenException(ErrorCode.INVALID_REFRESH_TOKEN));
LocalDateTime expireTime = findRefreshToken.getExpireTime();
LocalDateTime current = LocalDateTime.now();
// 테스트용, 실제로는 현재 시간 + accessToken 만료 시간
LocalDateTime expireDeadLine = current.plusSeconds(20);

Member member =
memberRepository
Expand All @@ -80,13 +78,8 @@ public RefreshToken reGenerateRefreshToken(MemberRequest.ReissueDTO request) {
logger.error("이미 만료된 리프레시 토큰 발견");
throw new RefreshTokenException(ErrorCode.RELOGIN_EXCEPTION);
}

// 새로 발급할 accessToken보다 refreshToken이 먼저 만료 될 경우인가?
if (expireTime.isAfter(expireDeadLine)) {
logger.info("기존 리프레시 토큰 발급");
return findRefreshToken;
} else {
logger.info("accessToken보다 먼저 만료될 예정인 리프레시 토큰 발견");
else{
logger.info("리프레시 토큰과 access 토큰 재발급");
deleteRefreshToken(request.getRefreshToken());
return generateRefreshToken(member.getSocialId(), member.getSocialType());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public WebSecurityCustomizer webSecurityCustomizer() {
"/schedule",
"/v3/api-docs",
"/v3/api-docs/**",
"/docs/**","/fcms/**",
"/docs/**","/fcms/**","/members/auth/**",
"/briefings/temp");
}

Expand Down Expand Up @@ -138,6 +138,7 @@ public SecurityFilterChain JwtFilterChain(HttpSecurity http) throws Exception {
.authenticated();
authorize.requestMatchers("/v2/scraps/**").authenticated();
authorize.requestMatchers("/scraps/**").authenticated();
authorize.requestMatchers("/members/auth/token").permitAll();
authorize.anyRequest().authenticated();
})
.exceptionHandling(
Expand Down
4 changes: 2 additions & 2 deletions Briefing-Api/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ jwt:
secret: ${JWT_SECRET}
# secret : ${JWT_SECRET}
authorities-key: authoritiesKey
access-token-validity-in-seconds: 1210000000 # 30 m
access-token-validity-in-seconds: 30 # 30 m
refresh-token-validity-in-seconds: 1210000000 # 14 d

openai:
Expand Down Expand Up @@ -159,7 +159,7 @@ jwt:
secret: ${JWT_SECRET}
# secret : ${JWT_SECRET}
authorities-key: authoritiesKey
access-token-validity-in-seconds: 1210000000 # 30 m
access-token-validity-in-seconds: 1800 # 30 m
refresh-token-validity-in-seconds: 1210000000 # 14 d

openai:
Expand Down
Loading