Skip to content

Commit

Permalink
[fix] 회원 탈퇴 에러 수정 (#137)
Browse files Browse the repository at this point in the history
* [refac] delete unused request dto

* [fix] fix changing profile after revoke and rejoin

* [fix] fix feign request logic for apple login
  • Loading branch information
kgy1008 authored Jul 18, 2024
1 parent 61f1824 commit 87865e4
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public HankkiResponse<UserLoginResponse> login(
@PatchMapping("/auth/logout")
public HankkiResponse<Void> signOut(
@UserId final Long userId) {
authService.logOut(userId);
authService.logout(userId);
return HankkiResponse.success(CommonSuccessCode.OK);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public UserLoginResponse login(final String token, final UserLoginRequest reques
return UserLoginResponse.of(issuedToken, isRegistered);
}

public void logOut(final Long userId) {
public void logout(final Long userId) {
UserInfo findUserInfo = userInfoFinder.getUserInfo(userId);
findUserInfo.updateRefreshToken(null);
}
Expand Down Expand Up @@ -125,6 +125,7 @@ private User updateUserInfo(final User user) {
user.updateStatus(ACTIVE);
user.updateDeletedAt(null);
userInfoFinder.getUserInfo(user.getId()).updateNickname(user.getName());
userInfoFinder.getUserInfo(user.getId()).updateProfile();
return user;
}

Expand All @@ -144,7 +145,7 @@ private void validateRefreshToken(final String refreshToken, final Long userId)
String storedRefreshToken = getRefreshToken(userId);
jwtValidator.equalsRefreshToken(refreshToken, storedRefreshToken);
} catch (UnauthorizedException e) {
logOut(userId);
logout(userId);
throw e;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ public void updateRefreshToken(final String refreshToken) {
public void updateNickname(final String nickname) {
this.nickname = nickname;
}

public void updateProfile() {
this.profileImageUrl = ImageSelector.setRandomDefaultImageUrl();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public interface UserInfoRepository extends JpaRepository<UserInfo, Long> {
Optional<UserInfo> findByUserId(Long userId);

@Modifying
@Query("UPDATE UserInfo ui SET ui.refreshToken = null, ui.nickname = '알 수 없음' WHERE ui.user.id = :userId")
@Query("UPDATE UserInfo ui SET ui.refreshToken = null, ui.nickname = '알 수 없음', ui.profileImageUrl = null WHERE ui.user.id = :userId")
void softDeleteByUserId(Long userId);
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package org.hankki.hankkiserver.external.openfeign.apple;

import org.hankki.hankkiserver.external.openfeign.apple.dto.ApplePublicKeys;
import org.hankki.hankkiserver.external.openfeign.apple.dto.AppleRevokeRequest;
import org.hankki.hankkiserver.external.openfeign.apple.dto.AppleTokenRequest;
import org.hankki.hankkiserver.external.openfeign.apple.dto.AppleTokenResponse;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestPart;

@FeignClient(name = "appleClient", url = "https://appleid.apple.com/auth")
public interface AppleFeignClient {
Expand All @@ -16,8 +15,14 @@ public interface AppleFeignClient {
ApplePublicKeys getApplePublicKey();

@PostMapping(value = "/token", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
AppleTokenResponse getAppleTokens(AppleTokenRequest request);
AppleTokenResponse getAppleTokens(@RequestPart(value = "code") String code,
@RequestPart(value = "client_id") String client_id,
@RequestPart(value = "client_secret") String client_secret,
@RequestPart(value = "grant_type") String grant_type);

@PostMapping(value = "/revoke", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
void revoke(AppleRevokeRequest request);
void revoke(@RequestPart(value = "token") String token,
@RequestPart(value = "client_id") String client_id,
@RequestPart(value = "client_secret") String client_secret,
@RequestPart(value = "token_type_hint") String token_type_hint);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

import io.jsonwebtoken.Claims;
import lombok.RequiredArgsConstructor;

import lombok.extern.slf4j.Slf4j;
import org.hankki.hankkiserver.common.code.AuthErrorCode;
import org.hankki.hankkiserver.common.exception.BadRequestException;
import org.hankki.hankkiserver.external.openfeign.apple.dto.ApplePublicKeys;
import org.hankki.hankkiserver.external.openfeign.apple.dto.AppleTokenRequest;
import org.hankki.hankkiserver.external.openfeign.dto.SocialInfoDto;
import org.hankki.hankkiserver.external.openfeign.apple.dto.AppleRevokeRequest;
import org.hankki.hankkiserver.external.openfeign.apple.dto.AppleTokenResponse;
import org.hankki.hankkiserver.external.openfeign.dto.SocialInfoDto;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -42,8 +39,7 @@ public SocialInfoDto getAppleUserInfo(final String identityToken, final String n

public String getAppleRefreshToken(final String code, final String clientSecret) {
try {
AppleTokenResponse appleTokenResponse = appleFeignClient.getAppleTokens(
AppleTokenRequest.of(code, clientId, clientSecret));
AppleTokenResponse appleTokenResponse = appleFeignClient.getAppleTokens(code, clientId, clientSecret, "authorization_code");
log.info("Apple token response: {}", appleTokenResponse);
return appleTokenResponse.refreshToken();
} catch (Exception e) {
Expand All @@ -53,9 +49,7 @@ public String getAppleRefreshToken(final String code, final String clientSecret)
}

public void requestRevoke(final String refreshToken, final String clientSecret) {
AppleRevokeRequest appleRevokeRequest = AppleRevokeRequest.of(
refreshToken, clientId, clientSecret);
log.error("Revoke request: {}", appleRevokeRequest);
appleFeignClient.revoke(appleRevokeRequest);
appleFeignClient.revoke(refreshToken, clientId, clientSecret, "refresh_token");
log.error("Failed to revoke apple refresh token.");
}
}

This file was deleted.

This file was deleted.

0 comments on commit 87865e4

Please sign in to comment.