diff --git a/src/main/java/com/fullcar/core/config/jwt/JwtTokenProvider.java b/src/main/java/com/fullcar/core/config/jwt/JwtTokenProvider.java index 4712a61..1644979 100644 --- a/src/main/java/com/fullcar/core/config/jwt/JwtTokenProvider.java +++ b/src/main/java/com/fullcar/core/config/jwt/JwtTokenProvider.java @@ -8,7 +8,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component;; +import org.springframework.stereotype.Component; import java.security.Key; import java.util.Date; @@ -27,7 +27,6 @@ public class JwtTokenProvider { private Long refreshTokenExpireLength; private static final String AUTHORIZATION_HEADER = "Authorization"; - private static final String REFRESH_AUTHORIZATION_HEADER = "Refresh"; public String generateAccessToken(Member member) { Date now = new Date(); diff --git a/src/main/java/com/fullcar/member/application/auth/AppleAuthService.java b/src/main/java/com/fullcar/member/application/auth/AppleAuthService.java index 40a3c0e..ffdfe59 100644 --- a/src/main/java/com/fullcar/member/application/auth/AppleAuthService.java +++ b/src/main/java/com/fullcar/member/application/auth/AppleAuthService.java @@ -6,10 +6,10 @@ import com.fullcar.core.exception.BadRequestException; import com.fullcar.core.exception.UnauthorizedException; import com.fullcar.core.response.ErrorCode; +import com.fullcar.member.application.member.MemberMapper; import com.fullcar.member.domain.auth.SocialId; import com.fullcar.member.domain.auth.service.SocialIdService; import com.fullcar.member.domain.member.Member; -import com.fullcar.member.domain.member.service.MemberIdService; import com.fullcar.member.domain.member.MemberRepository; import com.fullcar.member.presentation.auth.dto.request.AuthRequestDto; import com.fullcar.member.presentation.auth.dto.response.SocialInfoResponseDto; @@ -24,6 +24,7 @@ import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.client.RestTemplate; +import org.springframework.beans.factory.annotation.Value; import java.math.BigInteger; import java.security.KeyFactory; @@ -37,12 +38,17 @@ @RequiredArgsConstructor public class AppleAuthService implements AuthService { + @Value("${apple.client-id}") + private String clientId; + + @Value("${apple.iss}") + private String iss; + private final ObjectMapper objectMapper; private final JwtTokenProvider jwtTokenProvider; private final MemberRepository memberRepository; - private final MemberIdService memberIdService; + private final MemberMapper memberMapper; private final SocialIdService socialIdService; - private final AppleProperties appleProperties; @Override @Transactional @@ -73,17 +79,13 @@ public SocialInfoResponseDto getMemberInfo(AuthRequestDto authRequestDto) { // 새로운 멤버 생성 private void createMember(SocialId socialId, String deviceToken, String refreshToken) { - memberRepository.save(Member.builder() - .id(memberIdService.nextId()) - .socialId(socialId) - .deviceToken(deviceToken) - .refreshToken(refreshToken) - .build()); + Member member = memberMapper.toLoginEntity(socialId, deviceToken, refreshToken); + memberRepository.saveAndFlush(member); } // Claim 검증 private void validateClaims(Claims claims) { - if (!claims.getIssuer().contains(appleProperties.getIss()) || !claims.getAudience().equals(appleProperties.getClientId())) { + if (!claims.getIssuer().contains(iss) || !claims.getAudience().equals(clientId)) { throw new UnauthorizedException(ErrorCode.INVALID_CLAIMS); } } diff --git a/src/main/java/com/fullcar/member/application/auth/AppleProperties.java b/src/main/java/com/fullcar/member/application/auth/AppleProperties.java index 8250b8e..a66ea07 100644 --- a/src/main/java/com/fullcar/member/application/auth/AppleProperties.java +++ b/src/main/java/com/fullcar/member/application/auth/AppleProperties.java @@ -1,12 +1,13 @@ package com.fullcar.member.application.auth; -import lombok.Getter; -import org.springframework.boot.context.properties.ConfigurationProperties; +import lombok.*; import org.springframework.stereotype.Component; @Component -@ConfigurationProperties(prefix = "apple") @Getter +@Builder +@AllArgsConstructor(access = AccessLevel.PROTECTED) +@NoArgsConstructor(access = AccessLevel.PROTECTED) public class AppleProperties { private String teamId; private String keyId; diff --git a/src/main/java/com/fullcar/member/application/auth/KakaoAuthService.java b/src/main/java/com/fullcar/member/application/auth/KakaoAuthService.java index 1bbf65d..4e66cb8 100644 --- a/src/main/java/com/fullcar/member/application/auth/KakaoAuthService.java +++ b/src/main/java/com/fullcar/member/application/auth/KakaoAuthService.java @@ -6,10 +6,10 @@ import com.fullcar.core.config.jwt.JwtTokenProvider; import com.fullcar.core.exception.NotFoundException; import com.fullcar.core.response.ErrorCode; +import com.fullcar.member.application.member.MemberMapper; import com.fullcar.member.domain.auth.SocialId; import com.fullcar.member.domain.auth.service.SocialIdService; import com.fullcar.member.domain.member.Member; -import com.fullcar.member.domain.member.service.MemberIdService; import com.fullcar.member.domain.member.MemberRepository; import com.fullcar.member.presentation.auth.dto.request.AuthRequestDto; import com.fullcar.member.presentation.auth.dto.response.SocialInfoResponseDto; @@ -34,8 +34,8 @@ public class KakaoAuthService implements AuthService { private final JwtTokenProvider jwtTokenProvider; private final MemberRepository memberRepository; - private final MemberIdService memberIdService; private final SocialIdService socialIdService; + private final MemberMapper memberMapper; @Override @Transactional @@ -86,11 +86,7 @@ private static String getKakaoData(String kakaoToken) { // 새로운 멤버 생성 private void createMember(SocialId socialId, String deviceToken, String refreshToken) { - memberRepository.save(Member.builder() - .id(memberIdService.nextId()) - .socialId(socialId) - .deviceToken(deviceToken) - .refreshToken(refreshToken) - .build()); + Member member = memberMapper.toLoginEntity(socialId, deviceToken, refreshToken); + memberRepository.saveAndFlush(member); } } diff --git a/src/main/java/com/fullcar/member/application/member/MemberMapper.java b/src/main/java/com/fullcar/member/application/member/MemberMapper.java index 0e66375..9ec96ae 100644 --- a/src/main/java/com/fullcar/member/application/member/MemberMapper.java +++ b/src/main/java/com/fullcar/member/application/member/MemberMapper.java @@ -1,6 +1,8 @@ package com.fullcar.member.application.member; +import com.fullcar.member.domain.auth.SocialId; import com.fullcar.member.domain.member.Company; +import com.fullcar.member.domain.member.service.MemberIdService; import com.fullcar.member.infra.EmailMessage; import com.fullcar.member.domain.member.Member; import com.fullcar.member.presentation.member.dto.request.EmailRequestDto; @@ -14,6 +16,8 @@ @RequiredArgsConstructor(access = AccessLevel.PROTECTED) public class MemberMapper { + private final MemberIdService memberIdService; + public MemberGetResponseDto toDto(Member member) { return MemberGetResponseDto.builder() .nickname(member.getNickname()) @@ -45,4 +49,13 @@ public Member toEntity(OnboardingRequestDto onboardingRequestDto) { .gender(onboardingRequestDto.getGender()) .build(); } + + public Member toLoginEntity(SocialId socialId, String deviceToken, String refreshToken) { + return Member.builder() + .id(memberIdService.nextId()) + .socialId(socialId) + .deviceToken(deviceToken) + .refreshToken(refreshToken) + .build(); + } }