diff --git a/src/docs/asciidoc/api/user/user.adoc b/src/docs/asciidoc/api/user/user.adoc index e479be5..eeecf6c 100644 --- a/src/docs/asciidoc/api/user/user.adoc +++ b/src/docs/asciidoc/api/user/user.adoc @@ -1,40 +1,26 @@ === 소셜로그인 API -==== 카카오 로그인 [source,http,options="nowrap"] ---- -1. 카카오 로그인 페이지 +- 카카오 로그인 페이지 https://kauth.kakao.com/oauth/authorize?client_id=e372da97369cf835ea1691792daa9370&redirect_uri=http://ec2-52-78-18-124.ap-northeast-2.compute.amazonaws.com/login/kakao&response_type=code -2. 카카오 로그인 RedirectURL -GET -> /login/kakao - -3. 로그인 성공시 RedirectURL로 자동 이동 ----- - -==== 구글 로그인 -[source,http,options="nowrap"] ----- -1. 구글 로그인 페이지 +- 구글 로그인 페이지 https://accounts.google.com/o/oauth2/v2/auth?client_id=848453248473-levss4uvgkrum3h46knam82hlv83phvr.apps.googleusercontent.com&redirect_uri=http://ec2-52-78-18-124.ap-northeast-2.compute.amazonaws.com/login/google&response_type=code&scope=email%20profile%20openid&access_type=offline -2. 구글 로그인 RedirectURL -GET -> /login/google +1. 소셜 로그인 RedirectURL +GET -> /auth/signin -3. 로그인 성공시 RedirectURL로 자동 이동 +2. 로그인 성공시 RedirectURL로 자동 이동 ---- ==== HTTP Request QueryParameter -include::{snippets}/login-by-kakao/http-request.adoc[] -[source,http,options="nowrap"] ----- -GET /login/google?code=4%252F0AdEu5BVdKyrEElZENWgSJOrJSHUeAjsSJHvWUSi237TQ13FqUfqPOa-ZcES6lGID7DmVaJwSig HTTP/1.1 ----- -include::{snippets}/login-by-kakao/query-parameters.adoc[] +include::{snippets}/login-by-social/http-request.adoc[] +include::{snippets}/login-by-social/query-parameters.adoc[] ==== HTTP Response Body -include::{snippets}/login-by-kakao/http-response.adoc[] -include::{snippets}/login-by-kakao/response-fields.adoc[] +include::{snippets}/login-by-social/http-response.adoc[] +include::{snippets}/login-by-social/response-fields.adoc[] === 관심분야 추가 요청 API diff --git a/src/main/java/dnd/project/domain/user/config/Platform.java b/src/main/java/dnd/project/domain/user/config/Platform.java index 738476a..677d42b 100644 --- a/src/main/java/dnd/project/domain/user/config/Platform.java +++ b/src/main/java/dnd/project/domain/user/config/Platform.java @@ -4,5 +4,5 @@ @Getter public enum Platform { - NAVER, GOOGLE, KAKAO; + GOOGLE, KAKAO; } diff --git a/src/main/java/dnd/project/domain/user/controller/UserController.java b/src/main/java/dnd/project/domain/user/controller/UserController.java index 34fce9f..41f1184 100644 --- a/src/main/java/dnd/project/domain/user/controller/UserController.java +++ b/src/main/java/dnd/project/domain/user/controller/UserController.java @@ -1,5 +1,6 @@ package dnd.project.domain.user.controller; +import dnd.project.domain.user.config.Platform; import dnd.project.domain.user.request.controller.UserRequest; import dnd.project.domain.user.response.UserResponse; import dnd.project.domain.user.service.UserService; @@ -9,29 +10,23 @@ import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; -import static dnd.project.domain.user.config.Platform.GOOGLE; -import static dnd.project.domain.user.config.Platform.KAKAO; - @RestController @RequiredArgsConstructor +@RequestMapping("/auth") public class UserController { private final UserService userService; - // 카카오 로그인 API - @GetMapping("/login/kakao") - public CustomResponseEntity loginByKakao(@RequestParam String code) { - return CustomResponseEntity.success(userService.loginByOAuth(code, KAKAO)); - } - - // 구글 로그인 API - @GetMapping("/login/google") - public CustomResponseEntity loginByGoogle(@RequestParam String code) { - return CustomResponseEntity.success(userService.loginByOAuth(code, GOOGLE)); + // 소셜 로그인 API + @GetMapping("/signin") + public CustomResponseEntity loginByOAuth( + @RequestParam String code, @RequestParam Platform platform + ) { + return CustomResponseEntity.success(userService.loginByOAuth(code, platform)); } // 관심분야 추가 요청 API - @PostMapping("/auth") + @PostMapping("") public CustomResponseEntity addInterests( @AuthenticationPrincipal Long userId, UserRequest.Interests request ) { @@ -39,7 +34,7 @@ public CustomResponseEntity addInterests( } // 내 프로필 조회하기 API - @GetMapping("/auth") + @GetMapping("") public CustomResponseEntity detailUser( @AuthenticationPrincipal Long userId ) { @@ -47,7 +42,7 @@ public CustomResponseEntity detailUser( } // 내 정보 수정하기 API - @PatchMapping("/auth") + @PatchMapping("") public CustomResponseEntity updateUser( @RequestBody @Valid UserRequest.Update request, @AuthenticationPrincipal Long userId ) { diff --git a/src/main/java/dnd/project/global/config/SecurityConfig.java b/src/main/java/dnd/project/global/config/SecurityConfig.java index ab9be09..125accc 100644 --- a/src/main/java/dnd/project/global/config/SecurityConfig.java +++ b/src/main/java/dnd/project/global/config/SecurityConfig.java @@ -8,7 +8,6 @@ import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; @@ -52,7 +51,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { .authorizeHttpRequests((request) -> request .requestMatchers( "/api/v1/version", "/auth","/auth/admin", - "/login/kakao", "/login/google", "/docs/*", + "/auth/signin", "/docs/*", "/lectures","/lectures/scope", "/review/recent","/review/keyword" ) diff --git a/src/test/java/dnd/project/docs/user/UserControllerDocsTest.java b/src/test/java/dnd/project/docs/user/UserControllerDocsTest.java index ce58b18..663db39 100644 --- a/src/test/java/dnd/project/docs/user/UserControllerDocsTest.java +++ b/src/test/java/dnd/project/docs/user/UserControllerDocsTest.java @@ -38,7 +38,7 @@ protected Object initController() { return new UserController(userService); } - @DisplayName("카카오 로그인 API") + @DisplayName("소셜 로그인 API") @Test void loginByKakao() throws Exception { // given @@ -57,16 +57,19 @@ void loginByKakao() throws Exception { // when // then mockMvc.perform( - RestDocumentationRequestBuilders.get("/login/kakao") + RestDocumentationRequestBuilders.get("/auth/signin") .param("code", "4%2F0AdEu5BVdKyrEElZENWgSJOrJSHUeAjsSJHvWUSi237TQ13FqUfqPOa-ZcES6lGID7DmVaJwSig") + .param("platform","KAKAO") ) .andDo(print()) .andExpect(status().isOk()) - .andDo(document("login-by-kakao", + .andDo(document("login-by-social", preprocessResponse(prettyPrint()), queryParameters( parameterWithName("code") - .description("소셜 로그인 후 발급된 인가코드") + .description("소셜 로그인 후 발급된 인가코드"), + parameterWithName("platform") + .description("'KAKAO' / 'GOOGLE'") ), responseFields( fieldWithPath("code").type(NUMBER) diff --git a/src/test/java/dnd/project/domain/user/controller/UserControllerTest.java b/src/test/java/dnd/project/domain/user/controller/UserControllerTest.java index f75c61f..6fea1df 100644 --- a/src/test/java/dnd/project/domain/user/controller/UserControllerTest.java +++ b/src/test/java/dnd/project/domain/user/controller/UserControllerTest.java @@ -1,12 +1,9 @@ package dnd.project.domain.user.controller; -import com.fasterxml.jackson.databind.ObjectMapper; import dnd.project.domain.ControllerTestSupport; import dnd.project.domain.user.request.controller.UserRequest; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.ResultActions; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import java.util.List; @@ -17,14 +14,15 @@ class UserControllerTest extends ControllerTestSupport { - @DisplayName("카카오 로그인 API") + @DisplayName("소셜 로그인 API") @Test void loginByKakao() throws Exception { // given // when // then mockMvc.perform( - MockMvcRequestBuilders.get("/login/kakao") + MockMvcRequestBuilders.get("/auth/signin") .param("code", "4%2F0AdEu5BVdKyrEElZENWgSJOrJSHUeAjsSJHvWUSi237TQ13FqUfqPOa-ZcES6lGID7DmVaJwSig") + .param("platform","KAKAO") ) .andDo(print()) .andExpect(status().isOk());