diff --git a/src/main/java/org/hankki/hankkiserver/api/auth/controller/AuthController.java b/src/main/java/org/hankki/hankkiserver/api/auth/controller/AuthController.java index 309e22f0..d499167e 100644 --- a/src/main/java/org/hankki/hankkiserver/api/auth/controller/AuthController.java +++ b/src/main/java/org/hankki/hankkiserver/api/auth/controller/AuthController.java @@ -31,7 +31,7 @@ public HankkiResponse login( @PatchMapping("/auth/logout") public HankkiResponse signOut( @UserId final Long userId) { - authService.logOut(userId); + authService.logout(userId); return HankkiResponse.success(CommonSuccessCode.OK); } diff --git a/src/main/java/org/hankki/hankkiserver/api/auth/service/AuthService.java b/src/main/java/org/hankki/hankkiserver/api/auth/service/AuthService.java index 4dd88887..03fd553f 100644 --- a/src/main/java/org/hankki/hankkiserver/api/auth/service/AuthService.java +++ b/src/main/java/org/hankki/hankkiserver/api/auth/service/AuthService.java @@ -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); } @@ -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; } @@ -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; } } diff --git a/src/main/java/org/hankki/hankkiserver/domain/user/model/UserInfo.java b/src/main/java/org/hankki/hankkiserver/domain/user/model/UserInfo.java index 73d64e50..49987da3 100644 --- a/src/main/java/org/hankki/hankkiserver/domain/user/model/UserInfo.java +++ b/src/main/java/org/hankki/hankkiserver/domain/user/model/UserInfo.java @@ -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(); + } } diff --git a/src/main/java/org/hankki/hankkiserver/domain/user/repository/UserInfoRepository.java b/src/main/java/org/hankki/hankkiserver/domain/user/repository/UserInfoRepository.java index 91aa6b33..36e06d2e 100644 --- a/src/main/java/org/hankki/hankkiserver/domain/user/repository/UserInfoRepository.java +++ b/src/main/java/org/hankki/hankkiserver/domain/user/repository/UserInfoRepository.java @@ -13,6 +13,6 @@ public interface UserInfoRepository extends JpaRepository { Optional 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); } diff --git a/src/main/java/org/hankki/hankkiserver/external/openfeign/apple/AppleFeignClient.java b/src/main/java/org/hankki/hankkiserver/external/openfeign/apple/AppleFeignClient.java index cd1096d5..a11afcb1 100644 --- a/src/main/java/org/hankki/hankkiserver/external/openfeign/apple/AppleFeignClient.java +++ b/src/main/java/org/hankki/hankkiserver/external/openfeign/apple/AppleFeignClient.java @@ -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 { @@ -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); } diff --git a/src/main/java/org/hankki/hankkiserver/external/openfeign/apple/AppleOAuthProvider.java b/src/main/java/org/hankki/hankkiserver/external/openfeign/apple/AppleOAuthProvider.java index d55b81b5..58df6257 100644 --- a/src/main/java/org/hankki/hankkiserver/external/openfeign/apple/AppleOAuthProvider.java +++ b/src/main/java/org/hankki/hankkiserver/external/openfeign/apple/AppleOAuthProvider.java @@ -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; @@ -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) { @@ -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."); } } diff --git a/src/main/java/org/hankki/hankkiserver/external/openfeign/apple/dto/AppleRevokeRequest.java b/src/main/java/org/hankki/hankkiserver/external/openfeign/apple/dto/AppleRevokeRequest.java deleted file mode 100644 index 0b15999a..00000000 --- a/src/main/java/org/hankki/hankkiserver/external/openfeign/apple/dto/AppleRevokeRequest.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.hankki.hankkiserver.external.openfeign.apple.dto; - -public record AppleRevokeRequest( - String token, - String client_id, - String client_secret, - String token_type_hint -) { - - private static final String TOKEN_TYPE_HINT = "refresh_token"; - - public static AppleRevokeRequest of(String token, String client_id, String client_secret) { - return new AppleRevokeRequest(token, client_id, client_secret, TOKEN_TYPE_HINT); - } -} diff --git a/src/main/java/org/hankki/hankkiserver/external/openfeign/apple/dto/AppleTokenRequest.java b/src/main/java/org/hankki/hankkiserver/external/openfeign/apple/dto/AppleTokenRequest.java deleted file mode 100644 index aea7df31..00000000 --- a/src/main/java/org/hankki/hankkiserver/external/openfeign/apple/dto/AppleTokenRequest.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.hankki.hankkiserver.external.openfeign.apple.dto; - -public record AppleTokenRequest( - String code, - String client_id, - String client_secret, - String grant_type -) { - private static final String GRANT_TYPE = "authorization_code"; - - public static AppleTokenRequest of(String code, String client_id, String client_secret) { - return new AppleTokenRequest(code, client_id, client_secret, GRANT_TYPE); - } -}