Skip to content

Commit

Permalink
add: apple properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Seokyeong237 committed Feb 7, 2024
1 parent d68c944 commit 62d05f7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
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

0 comments on commit 62d05f7

Please sign in to comment.