Skip to content

Commit

Permalink
Fix: OauthService.revokeOauth()에서 oidc revoke 요청을 기다렸다가 성공 여부를 반환하도록 …
Browse files Browse the repository at this point in the history
…수정 (#270)
  • Loading branch information
Jaewon-pro authored Oct 20, 2024
1 parent 3aa6cbd commit 5387fd6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
32 changes: 14 additions & 18 deletions src/main/java/com/dnd/runus/application/oauth/OauthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public SignResponse signUp(SignUpRequest request) {
}

@Transactional(readOnly = true)
public void revokeOauth(long memberId, WithdrawRequest request) {
public boolean revokeOauth(long memberId, WithdrawRequest request) {

memberRepository.findById(memberId).orElseThrow(() -> new NotFoundException(Member.class, memberId));

Expand All @@ -93,23 +93,19 @@ public void revokeOauth(long memberId, WithdrawRequest request) {
String.format(
"socialType: %s, oauthId: %s, memberId: %s", request.socialType(), oauthId, memberId)));

Thread.startVirtualThread(() -> {
try {
String accessToken = oidcProvider.getAccessToken(request.authorizationCode());
oidcProvider.revoke(accessToken);
log.info("토큰 revoke 성공. memberId: {}, socialType: {}", memberId, request.socialType());
} catch (Exception e) {
log.warn(
"토큰 revoke 실패. memberId: {}, socialType: {}, {}",
memberId,
request.socialType(),
e.getMessage());
}
});
log.info("토큰 revoke 요청 완료. memberId: {}, socialType: {}", memberId, request.socialType());

AfterTransactionEvent withDrawEvent = () -> memberWithdrawService.deleteAllDataAboutMember(memberId);
eventPublisher.publishEvent(withDrawEvent);
try {
String accessToken = oidcProvider.getAccessToken(request.authorizationCode());
oidcProvider.revoke(accessToken);
log.info("토큰 revoke 성공. memberId: {}, socialType: {}", memberId, request.socialType());

AfterTransactionEvent withDrawEvent = () -> memberWithdrawService.deleteAllDataAboutMember(memberId);
eventPublisher.publishEvent(withDrawEvent);

return true;
} catch (Exception e) {
log.warn("토큰 revoke 실패. memberId: {}, socialType: {}, {}", memberId, request.socialType(), e.getMessage());
return false;
}
}

private SocialProfile createMember(String oauthId, String email, SocialType socialType, String nickname) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.dnd.runus.presentation.v1.oauth.dto.request.SignUpRequest;
import com.dnd.runus.presentation.v1.oauth.dto.request.WithdrawRequest;
import com.dnd.runus.presentation.v1.oauth.dto.response.SignResponse;
import com.dnd.runus.presentation.v1.oauth.dto.response.WithdrawResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
Expand Down Expand Up @@ -76,7 +77,9 @@ public SignResponse signUp(@Valid @RequestBody SignUpRequest request) {
@ApiErrorType({ErrorType.UNSUPPORTED_SOCIAL_TYPE, ErrorType.FAILED_AUTHENTICATION})
@PostMapping("/withdraw")
@ResponseStatus(HttpStatus.OK)
public void withdraw(@MemberId long memberId, @Valid @RequestBody WithdrawRequest request) {
oauthService.revokeOauth(memberId, request);
public WithdrawResponse withdraw(@MemberId long memberId, @Valid @RequestBody WithdrawRequest request) {
boolean isSuccess = oauthService.revokeOauth(memberId, request);

return new WithdrawResponse(isSuccess);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.dnd.runus.presentation.v1.oauth.dto.response;

public record WithdrawResponse(
boolean isWithdrawSuccess
) {
}

0 comments on commit 5387fd6

Please sign in to comment.