Skip to content

Commit

Permalink
Merge pull request #68 from YAPP-Github/refactor/ISSUE-67
Browse files Browse the repository at this point in the history
refactor: social login API
  • Loading branch information
Seokyeong237 authored Feb 8, 2024
2 parents 340689b + 62d05f7 commit 9b96d77
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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())
Expand Down Expand Up @@ -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();
}
}

0 comments on commit 9b96d77

Please sign in to comment.