Skip to content

Commit

Permalink
remove: 회원 탈퇴 v2 api를 삭제한다.
Browse files Browse the repository at this point in the history
  • Loading branch information
rlarltj committed May 12, 2024
1 parent 97c97c8 commit 478bea6
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 45 deletions.
29 changes: 0 additions & 29 deletions src/main/java/com/moneymong/domain/user/api/UserControllerV2.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,9 @@ public LoginSuccessResponse login(LoginRequest loginRequest) {

@Transactional
public void delete(Long userId) {
oAuthService.revoke(userId);
userService.delete(userId);
userUniversityService.delete(userId);
agencyUserService.deleteAll(userId);
}

@Transactional
public void revoke(UserDeleteRequest deleteRequest, Long userId) {
oAuthService.revoke(deleteRequest, userId);
delete(userId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public enum ErrorCode {

// ---- 유저 ---- //
USER_NOT_FOUND(MoneymongConstant.NOT_FOUND, "USER-001", "존재하지 않는 회원입니다."),
USER_NOT_FOUND_APPLE(MoneymongConstant.NOT_FOUND, "USER-002", "존재하지 않는 APPLE 유저입니다."),

// ---- 대학교 ---- //
USER_UNIVERSITY_NOT_FOUND(MoneymongConstant.NOT_FOUND, "UNIVERSITY-001", "회원의 대학 정보가 존재하지 않습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.auth0.jwt.interfaces.DecodedJWT;
import com.moneymong.domain.user.entity.AppleUser;
import com.moneymong.domain.user.repository.AppleUserRepository;
import com.moneymong.global.exception.custom.NotFoundException;
import com.moneymong.global.exception.enums.ErrorCode;
import com.moneymong.global.security.oauth.dto.AppleUserData;
import com.moneymong.global.security.oauth.dto.OAuthUserDataRequest;
Expand All @@ -22,7 +23,6 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.*;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestClientException;
Expand All @@ -32,10 +32,11 @@
import java.net.URI;
import java.security.PrivateKey;
import java.security.Security;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.*;

import static com.moneymong.global.exception.enums.ErrorCode.USER_NOT_FOUND_APPLE;

@Slf4j
@Component
@RequiredArgsConstructor
Expand Down Expand Up @@ -82,7 +83,7 @@ public OAuthUserDataResponse getOAuthUserData(OAuthUserDataRequest request) {
parameterMap.add("code", request.getCode());

URI uri = UriComponentsBuilder
.fromUriString(host + "/auth/token")
.fromUriString(host + "/auth/oauth2/v2/token")
.queryParams(parameterMap)
.build()
.toUri();
Expand All @@ -102,7 +103,6 @@ public OAuthUserDataResponse getOAuthUserData(OAuthUserDataRequest request) {
log.info("[AppleService] refreshToken = {}", refreshToken);
return decodePayload(idToken, request.getName(), refreshToken);
} catch (RestClientException e) {
log.info("[AppleService] error message = {}", e.getMessage());
log.warn("[AppleService] failed to get OAuth User Data = {}", request.getAccessToken());
throw new HttpClientException(ErrorCode.HTTP_CLIENT_REQUEST_FAILED);
}
Expand All @@ -111,7 +111,7 @@ public OAuthUserDataResponse getOAuthUserData(OAuthUserDataRequest request) {
@Override
public void unlink(Long userId) {
AppleUser appleUser = appleUserRepository.findAppleUserByUserId(userId)
.orElseThrow(() -> new RuntimeException());
.orElseThrow(() -> new NotFoundException(USER_NOT_FOUND_APPLE));

String refreshToken = appleUser.getAppleRefreshToken();
String clientSecret = createClientSecret();
Expand All @@ -123,7 +123,7 @@ public void unlink(Long userId) {
params.add("token_type_hint", "refresh_token");

URI uri = UriComponentsBuilder
.fromUriString(host + "/auth/revoke")
.fromUriString(host + "/auth/oauth2/v2/revoke")
.build()
.toUri();

Expand Down Expand Up @@ -177,7 +177,6 @@ private OAuthUserDataResponse decodePayload(String idToken, String nickname, Str
DecodedJWT decoded = JWT.decode(idToken);
Map<String, Claim> claims = decoded.getClaims();

log.info("[AppleService] claims = {}", claims.keySet());
String providerUid = decoded.getSubject();
String email = claims.get("sub").asString();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,34 @@

import com.moneymong.domain.user.api.request.LoginRequest;
import com.moneymong.domain.user.api.request.UserDeleteRequest;
import com.moneymong.domain.user.entity.User;
import com.moneymong.domain.user.repository.UserRepository;
import com.moneymong.global.exception.custom.NotFoundException;
import com.moneymong.global.exception.enums.ErrorCode;
import com.moneymong.global.security.oauth.dto.OAuthUserDataRequest;
import com.moneymong.global.security.oauth.dto.OAuthUserDataResponse;
import com.moneymong.global.security.oauth.handler.OAuthAuthenticationHandler;
import jakarta.persistence.EntityNotFoundException;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

import static com.moneymong.global.exception.enums.ErrorCode.USER_NOT_FOUND;

@Service
public class OAuthService {

private final Map<OAuthProvider, OAuthAuthenticationHandler> oAuthAuthenticationHandlers;
private final UserRepository userRepository;

public OAuthService(List<OAuthAuthenticationHandler> oAuthAuthenticationHandlers) {
public OAuthService(List<OAuthAuthenticationHandler> oAuthAuthenticationHandlers, UserRepository userRepository) {
this.oAuthAuthenticationHandlers = oAuthAuthenticationHandlers.stream().collect(
Collectors.toConcurrentMap(OAuthAuthenticationHandler::getAuthProvider, Function.identity())
);
this.userRepository = userRepository;
}

public OAuthUserDataResponse login(LoginRequest loginRequest) {
Expand All @@ -37,8 +46,12 @@ public OAuthUserDataResponse login(LoginRequest loginRequest) {
return oAuthHandler.getOAuthUserData(request);
}

public void revoke(UserDeleteRequest deleteRequest, Long userId) {
OAuthProvider oAuthProvider = OAuthProvider.get(deleteRequest.getProvider());
public void revoke(Long userId) {
User user = userRepository
.findById(userId)
.orElseThrow(() -> new NotFoundException(USER_NOT_FOUND));

OAuthProvider oAuthProvider = OAuthProvider.get(user.getProvider());
OAuthAuthenticationHandler oAuthHandler = this.oAuthAuthenticationHandlers.get(oAuthProvider);

oAuthHandler.unlink(userId);
Expand Down

0 comments on commit 478bea6

Please sign in to comment.