Skip to content

Commit

Permalink
Merge pull request #25 from coffee-meet/feat/#23
Browse files Browse the repository at this point in the history
Feat/#23 리프레시 토큰 저장 기능 구현
  • Loading branch information
yumyeonghan authored Oct 23, 2023
2 parents 5588ad0 + 5976154 commit d3be467
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package coffeemeet.server.auth;
package coffeemeet.server.auth.infrastructure;

import coffeemeet.server.auth.domain.RefreshToken;
import org.springframework.data.repository.CrudRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package coffeemeet.server.auth.utils;

import coffeemeet.server.auth.domain.RefreshToken;
import coffeemeet.server.auth.infrastructure.RefreshTokenRepository;
import java.util.Date;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
Expand All @@ -12,14 +14,16 @@ public class AuthTokensGenerator {
private final JwtTokenProvider jwtTokenProvider;
private final Long accessTokenExpireTime;
private final Long refreshTokenExpireTime;
private final RefreshTokenRepository refreshTokenRepository;

public AuthTokensGenerator(JwtTokenProvider jwtTokenProvider,
@Value("${jwt.access-token-expire-time}") Long accessTokenExpireTime,
@Value("${jwt.refresh-token-expire-time}") Long refreshTokenExpireTime
) {
@Value("${jwt.refresh-token-expire-time}") Long refreshTokenExpireTime,
RefreshTokenRepository refreshTokenRepository) {
this.jwtTokenProvider = jwtTokenProvider;
this.accessTokenExpireTime = accessTokenExpireTime;
this.refreshTokenExpireTime = refreshTokenExpireTime;
this.refreshTokenRepository = refreshTokenRepository;
}

public AuthTokens generate(Long userId) {
Expand All @@ -31,6 +35,12 @@ public AuthTokens generate(Long userId) {
String accessToken = jwtTokenProvider.generate(subject, accessTokenExpiredAt);
String refreshToken = jwtTokenProvider.generate(subject, refreshTokenExpiredAt);

RefreshToken refreshTokenEntity = RefreshToken.builder()
.userId(userId)
.value(refreshToken)
.build();
refreshTokenRepository.save(refreshTokenEntity);

return AuthTokens.of(
BEARER_TYPE + accessToken,
BEARER_TYPE + refreshToken
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package coffeemeet.server.common;

import coffeemeet.server.auth.RefreshTokenRepository;
import coffeemeet.server.auth.domain.RefreshToken;
import coffeemeet.server.auth.infrastructure.RefreshTokenRepository;
import coffeemeet.server.auth.utils.JwtTokenProvider;
import coffeemeet.server.common.annotation.Login;
import coffeemeet.server.user.dto.AuthInfo;
Expand All @@ -18,7 +18,7 @@
@RequiredArgsConstructor
public class UserArgumentResolver implements HandlerMethodArgumentResolver {

public static final String USER_AUTHENTICATION_FAILED_MESSAGE = "사용자(%s)의 갱신 토큰이 존재하지 않습니다.";
public static final String USER_AUTHENTICATION_FAILED_MESSAGE = "사용자(%s)의 재인증(로그인)이 필요합니다.";
private static final String HEADER_AUTHENTICATION_FAILED_MESSAGE = "(%s)는 잘못된 권한 헤더입니다.";

private final JwtTokenProvider jwtTokenProvider;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package coffeemeet.server.common.config;

import coffeemeet.server.auth.RefreshTokenRepository;
import coffeemeet.server.auth.infrastructure.RefreshTokenRepository;
import coffeemeet.server.auth.utils.JwtTokenProvider;
import coffeemeet.server.auth.utils.converter.OAuthProviderConverter;
import coffeemeet.server.common.UserArgumentResolver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;

import coffeemeet.server.auth.RefreshTokenRepository;
import coffeemeet.server.auth.infrastructure.RefreshTokenRepository;
import coffeemeet.server.auth.utils.JwtTokenProvider;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.BeforeEach;
Expand Down

0 comments on commit d3be467

Please sign in to comment.