Skip to content

Commit

Permalink
feat: 카카오 로그아웃 API 구현 (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdkdhoho committed Feb 6, 2024
1 parent 2ee6580 commit 8991815
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.listywave.auth.application.domain.kakao;

import com.listywave.auth.infra.kakao.KakaoOauthApiClient;
import com.listywave.auth.infra.kakao.response.KakaoLogoutResponse;
import com.listywave.auth.infra.kakao.response.KakaoMember;
import com.listywave.auth.infra.kakao.response.KakaoTokenResponse;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -30,4 +31,9 @@ public KakaoTokenResponse requestToken(String authCode) {
public KakaoMember fetchMember(String accessToken) {
return apiClient.fetchKakaoMember("Bearer " + accessToken);
}

public Long logout(String oauthAccessToken) {
KakaoLogoutResponse response = apiClient.logout(oauthAccessToken);
return response.id();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,10 @@ public LoginResponse login(String authCode) {
public String createToken(Long userId) {
return jwtManager.createToken(userId);
}

public void logout(String accessToken) {
Long userId = jwtManager.read(accessToken);
User user = userRepository.getById(userId);
kakaoOauthClient.logout(user.getKakaoAccessToken());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.springframework.http.HttpHeaders.AUTHORIZATION;

import com.listywave.auth.infra.kakao.response.KakaoLogoutResponse;
import com.listywave.auth.infra.kakao.response.KakaoMember;
import com.listywave.auth.infra.kakao.response.KakaoTokenResponse;
import org.springframework.util.MultiValueMap;
Expand All @@ -22,4 +23,7 @@ public interface KakaoOauthApiClient {
contentType = "application/x-www-form-urlencoded;charset=utf-8"
)
KakaoMember fetchKakaoMember(@RequestHeader(name = AUTHORIZATION) String accessToken);

@PostExchange(url = "https://kapi.kakao.com/v1/user/logout")
KakaoLogoutResponse logout(@RequestHeader(value = AUTHORIZATION) String accessToken);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.listywave.auth.infra.kakao.response;

public record KakaoLogoutResponse(
Long id
) {
}
10 changes: 10 additions & 0 deletions src/main/java/com/listywave/auth/presentation/AuthController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.listywave.auth.presentation;

import static org.springframework.http.HttpHeaders.AUTHORIZATION;

import com.listywave.auth.application.dto.LoginResponse;
import com.listywave.auth.application.service.AuthService;
import jakarta.servlet.http.HttpServletResponse;
Expand All @@ -9,6 +11,8 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

Expand Down Expand Up @@ -38,4 +42,10 @@ ResponseEntity<LoginResponse> login(
response.setHeader(HttpHeaders.SET_COOKIE, accessToken);
return ResponseEntity.ok(loginResponse);
}

@PatchMapping("/auth/kakao")
ResponseEntity<Void> logout(@RequestHeader(value = AUTHORIZATION) String accessToken) {
authService.logout(accessToken);
return ResponseEntity.noContent().build();
}
}

0 comments on commit 8991815

Please sign in to comment.