-
Notifications
You must be signed in to change notification settings - Fork 0
[FEAT/#113] 회원탈퇴 시 OAuth revoke 연결 #114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
71d7b8f
feat: revoke 인터페이스 호출 추가
Kyoung-M1N b16b6e7
chore: 애플 토큰 발급용 라이브러리 의존성 추가
Kyoung-M1N 0d66a33
refactor: revoke 로직 파라미터 및 분기 처리 변경
Kyoung-M1N b15aebd
feat: revoke용 파라미터 추가
Kyoung-M1N 45e4bb3
chore: revoke 환경변수 추가
Kyoung-M1N 3d99bca
feat: revoke 로직 구현
Kyoung-M1N 93d8adf
test: 기존 서비스 로직 테스트 수정
Kyoung-M1N 9d81c78
fix: 미구현 영역 설명 제거
Kyoung-M1N 17a2ce6
refactor: 외부 요청 timeout 설정
Kyoung-M1N f08c8b5
style: 불필요 주석 제거
Kyoung-M1N 2d0b331
style: 스웨거 설명 수정
Kyoung-M1N File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
routee-external/src/main/java/org/sopt/routee/external/api/port/OAuthRevokePort.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package org.sopt.routee.external.api.port; | ||
|
|
||
| public interface OAuthRevokePort { | ||
|
|
||
| void revoke(String authorizationCode); | ||
| } |
76 changes: 76 additions & 0 deletions
76
...main/java/org/sopt/routee/external/internal/oauth/adapter/AppleClientSecretGenerator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| package org.sopt.routee.external.internal.oauth.adapter; | ||
|
|
||
| import java.security.GeneralSecurityException; | ||
| import java.security.KeyFactory; | ||
| import java.security.interfaces.ECPrivateKey; | ||
| import java.security.spec.PKCS8EncodedKeySpec; | ||
| import java.time.Duration; | ||
| import java.time.Instant; | ||
| import java.util.Base64; | ||
| import java.util.Date; | ||
| import java.util.concurrent.atomic.AtomicReference; | ||
|
|
||
| import org.sopt.routee.external.internal.oauth.config.OAuthRevokeProperty; | ||
| import org.sopt.routee.external.internal.oauth.exception.AppleClientSecretException; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import com.nimbusds.jose.JOSEException; | ||
| import com.nimbusds.jose.JWSAlgorithm; | ||
| import com.nimbusds.jose.JWSHeader; | ||
| import com.nimbusds.jose.crypto.ECDSASigner; | ||
| import com.nimbusds.jwt.JWTClaimsSet; | ||
| import com.nimbusds.jwt.SignedJWT; | ||
|
|
||
| @Component | ||
| class AppleClientSecretGenerator { | ||
|
|
||
| private static final Duration TOKEN_EXPIRY = Duration.ofMinutes(30); | ||
| private static final Duration CACHE_TTL = Duration.ofMinutes(25); | ||
|
|
||
| private final OAuthRevokeProperty property; | ||
| private final AtomicReference<CachedSecret> cache = new AtomicReference<>(); | ||
|
|
||
| AppleClientSecretGenerator(OAuthRevokeProperty property) { | ||
| this.property = property; | ||
| } | ||
|
|
||
| String generate() { | ||
| CachedSecret cached = cache.get(); | ||
| if (cached != null && cached.expiresAt().isAfter(Instant.now())) { | ||
| return cached.value(); | ||
| } | ||
|
|
||
| String secret = sign(); | ||
| cache.set(new CachedSecret(secret, Instant.now().plus(CACHE_TTL))); | ||
| return secret; | ||
| } | ||
|
|
||
| private String sign() { | ||
| try { | ||
| Instant now = Instant.now(); | ||
| SignedJWT jwt = new SignedJWT( | ||
| new JWSHeader.Builder(JWSAlgorithm.ES256).keyID(property.keyId()).build(), | ||
| new JWTClaimsSet.Builder() | ||
| .issuer(property.teamId()) | ||
| .issueTime(Date.from(now)) | ||
| .expirationTime(Date.from(now.plus(TOKEN_EXPIRY))) | ||
| .audience(property.audience()) | ||
| .subject(property.clientId()) | ||
| .build() | ||
| ); | ||
| jwt.sign(new ECDSASigner(parsePrivateKey(property.privateKey()))); | ||
| return jwt.serialize(); | ||
| } catch (JOSEException | GeneralSecurityException | IllegalArgumentException e) { | ||
| throw new AppleClientSecretException(e); | ||
| } | ||
| } | ||
|
|
||
| private ECPrivateKey parsePrivateKey(String privateKey) throws GeneralSecurityException { | ||
| byte[] der = Base64.getDecoder().decode(privateKey); | ||
| KeyFactory keyFactory = KeyFactory.getInstance("EC"); | ||
| return (ECPrivateKey)keyFactory.generatePrivate(new PKCS8EncodedKeySpec(der)); | ||
| } | ||
|
|
||
| private record CachedSecret(String value, Instant expiresAt) { | ||
| } | ||
| } |
81 changes: 81 additions & 0 deletions
81
...rc/main/java/org/sopt/routee/external/internal/oauth/adapter/AppleOAuthRevokeAdapter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| package org.sopt.routee.external.internal.oauth.adapter; | ||
|
|
||
| import org.sopt.routee.external.api.port.OAuthRevokePort; | ||
| import org.sopt.routee.external.internal.oauth.config.OAuthRevokeProperty; | ||
| import org.sopt.routee.external.internal.oauth.exception.OAuthRevokeException; | ||
| import org.springframework.http.MediaType; | ||
| import org.springframework.stereotype.Component; | ||
| import org.springframework.util.LinkedMultiValueMap; | ||
| import org.springframework.util.MultiValueMap; | ||
| import org.springframework.util.StringUtils; | ||
| import org.springframework.web.client.RestClient; | ||
| import org.springframework.web.client.RestClientException; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Component | ||
| @RequiredArgsConstructor | ||
| class AppleOAuthRevokeAdapter implements OAuthRevokePort { | ||
|
|
||
| private static final String REFRESH_TOKEN_HINT = "refresh_token"; | ||
|
|
||
| private final RestClient restClient; | ||
| private final OAuthRevokeProperty property; | ||
| private final AppleClientSecretGenerator clientSecretGenerator; | ||
|
|
||
| @Override | ||
| public void revoke(String authorizationCode) { | ||
| OAuthTokenResponse token = exchangeAuthorizationCode(authorizationCode); | ||
|
|
||
| if (!StringUtils.hasText(token.refreshToken())) { | ||
| throw new OAuthRevokeException(); | ||
| } | ||
|
|
||
| requestRevoke(token.refreshToken(), REFRESH_TOKEN_HINT); | ||
| } | ||
|
|
||
| private OAuthTokenResponse exchangeAuthorizationCode(String authorizationCode) { | ||
| MultiValueMap<String, String> form = credentialForm(); | ||
|
|
||
| form.add("grant_type", "authorization_code"); | ||
| form.add("code", authorizationCode); | ||
|
|
||
| OAuthTokenResponse response = post(property.tokenUri(), form, OAuthTokenResponse.class); | ||
|
|
||
| if (response == null) { | ||
| throw new OAuthRevokeException(); | ||
| } | ||
|
|
||
| return response; | ||
| } | ||
|
|
||
| private void requestRevoke(String token, String tokenTypeHint) { | ||
| MultiValueMap<String, String> form = credentialForm(); | ||
| form.add("token", token); | ||
| form.add("token_type_hint", tokenTypeHint); | ||
|
|
||
| post(property.revokeUri(), form, Void.class); | ||
| } | ||
|
|
||
| private <T> T post(String uri, MultiValueMap<String, String> form, Class<T> responseType) { | ||
| try { | ||
| return restClient.post() | ||
| .uri(uri) | ||
| .contentType(MediaType.APPLICATION_FORM_URLENCODED) | ||
| .body(form) | ||
| .retrieve() | ||
| .body(responseType); | ||
| } catch (RestClientException e) { | ||
| throw new OAuthRevokeException(e); | ||
| } | ||
| } | ||
|
|
||
| private MultiValueMap<String, String> credentialForm() { | ||
| MultiValueMap<String, String> form = new LinkedMultiValueMap<>(); | ||
|
|
||
| form.add("client_id", property.clientId()); | ||
| form.add("client_secret", clientSecretGenerator.generate()); | ||
|
|
||
| return form; | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
...nal/src/main/java/org/sopt/routee/external/internal/oauth/adapter/OAuthTokenResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package org.sopt.routee.external.internal.oauth.adapter; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
|
||
| record OAuthTokenResponse( | ||
| @JsonProperty("refresh_token") String refreshToken | ||
| ) { | ||
| } |
18 changes: 18 additions & 0 deletions
18
routee-external/src/main/java/org/sopt/routee/external/internal/oauth/code/ErrorCode.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package org.sopt.routee.external.internal.oauth.code; | ||
|
|
||
| import org.sopt.routee.code.ErrorResultCode; | ||
| import org.springframework.http.HttpStatus; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Getter | ||
| @RequiredArgsConstructor | ||
| public enum ErrorCode implements ErrorResultCode { | ||
|
|
||
| OAUTH_REVOKE_FAILED(HttpStatus.BAD_GATEWAY, "소셜 로그인 연동 해제에 실패했습니다."), | ||
| APPLE_CLIENT_SECRET_GENERATION_FAILED(HttpStatus.INTERNAL_SERVER_ERROR, "Apple client secret 생성에 실패했습니다."); | ||
|
|
||
| private final HttpStatus status; | ||
| private final String message; | ||
| } |
30 changes: 30 additions & 0 deletions
30
...src/main/java/org/sopt/routee/external/internal/oauth/config/OAuthRevokeClientConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package org.sopt.routee.external.internal.oauth.config; | ||
|
|
||
| import java.net.http.HttpClient; | ||
| import java.time.Duration; | ||
|
|
||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.http.client.JdkClientHttpRequestFactory; | ||
| import org.springframework.web.client.RestClient; | ||
|
|
||
| @Configuration | ||
| class OAuthRevokeClientConfig { | ||
|
|
||
| private static final Duration CONNECT_TIMEOUT = Duration.ofSeconds(5); | ||
| private static final Duration READ_TIMEOUT = Duration.ofSeconds(10); | ||
|
|
||
| @Bean | ||
| RestClient oauthRevokeRestClient() { | ||
| HttpClient httpClient = HttpClient.newBuilder() | ||
| .connectTimeout(CONNECT_TIMEOUT) | ||
| .build(); | ||
|
|
||
| JdkClientHttpRequestFactory requestFactory = new JdkClientHttpRequestFactory(httpClient); | ||
| requestFactory.setReadTimeout(READ_TIMEOUT); | ||
|
|
||
| return RestClient.builder() | ||
| .requestFactory(requestFactory) | ||
| .build(); | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
...nal/src/main/java/org/sopt/routee/external/internal/oauth/config/OAuthRevokeProperty.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package org.sopt.routee.external.internal.oauth.config; | ||
|
|
||
| import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
|
||
| @ConfigurationProperties(prefix = "oauth.providers.apple") | ||
| public record OAuthRevokeProperty( | ||
| String tokenUri, | ||
| String revokeUri, | ||
| String audience, | ||
| String clientId, | ||
| String teamId, | ||
| String keyId, | ||
| String privateKey | ||
| ) { | ||
| } |
11 changes: 11 additions & 0 deletions
11
...in/java/org/sopt/routee/external/internal/oauth/exception/AppleClientSecretException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package org.sopt.routee.external.internal.oauth.exception; | ||
|
|
||
| import org.sopt.routee.exception.BaseException; | ||
| import org.sopt.routee.external.internal.oauth.code.ErrorCode; | ||
|
|
||
| public final class AppleClientSecretException extends BaseException { | ||
|
|
||
| public AppleClientSecretException(Throwable cause) { | ||
| super(ErrorCode.APPLE_CLIENT_SECRET_GENERATION_FAILED, cause); | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
...src/main/java/org/sopt/routee/external/internal/oauth/exception/OAuthRevokeException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package org.sopt.routee.external.internal.oauth.exception; | ||
|
|
||
| import org.sopt.routee.exception.BaseException; | ||
| import org.sopt.routee.external.internal.oauth.code.ErrorCode; | ||
|
|
||
| public final class OAuthRevokeException extends BaseException { | ||
|
|
||
| public OAuthRevokeException() { | ||
| super(ErrorCode.OAUTH_REVOKE_FAILED); | ||
| } | ||
|
|
||
| public OAuthRevokeException(Throwable cause) { | ||
| super(ErrorCode.OAUTH_REVOKE_FAILED, cause); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 12 additions & 1 deletion
13
...src/main/java/org/sopt/routee/member/internal/controller/dto/request/WithdrawRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,20 @@ | ||
| package org.sopt.routee.member.internal.controller.dto.request; | ||
|
|
||
| import org.sopt.routee.member.internal.service.dto.command.WithdrawCommand; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import jakarta.validation.constraints.NotBlank; | ||
|
|
||
| public record WithdrawRequest( | ||
| @Schema(description = "탈퇴를 요청하는 회원의 리프레시 토큰. 모든 탈퇴 요청에 필수입니다.") | ||
| @NotBlank(message = "refresh_token은 필수입니다.") | ||
| String refreshToken | ||
| String refreshToken, | ||
|
|
||
| @Schema(description = "탈퇴 시점에 재인증하여 발급받은 Apple 인가 코드. Apple 계정 연동 해제에 사용되며, Apple 로그인 회원만 필요합니다. " | ||
| + "그 외 소셜 로그인 회원은 전달하지 않아도 됩니다.") | ||
| String authorizationCode | ||
| ) { | ||
| public WithdrawCommand toCommand(Long memberId, String accessTokenHash, String refreshTokenHash) { | ||
| return new WithdrawCommand(memberId, accessTokenHash, refreshTokenHash, authorizationCode); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: Team-Routee/Routee-Server
Length of output: 5762
🏁 Script executed:
Repository: Team-Routee/Routee-Server
Length of output: 42746
🏁 Script executed:
Repository: Team-Routee/Routee-Server
Length of output: 22753
Apple 회원은 삭제 전에
authorizationCode를 검증하십시오.WithdrawRequest는authorizationCode를 검증하지 않고WithdrawCommand로 전달합니다.MemberService.withdraw는 회원 삭제를 완료한 뒤AppleOAuthRevokeAdapter를 호출합니다. 코드가 없거나 비어 있으면 revoke 요청이 실패할 수 있으며, 해당BaseException은 로그만 남기고 무시됩니다. Apple 연동 해제가 누락된 상태로 회원 삭제가 완료될 수 있습니다. Apple 회원에게만 삭제 전에authorizationCode의null및 공백 여부를 검증하십시오. Google 회원에는 이 검증을 적용하지 마십시오.🤖 Prompt for AI Agents