From 3c3576912b1e582199d306258674f4842a9e8c2d Mon Sep 17 00:00:00 2001 From: seungyeonnnnnni Date: Tue, 7 Nov 2023 16:31:16 +0900 Subject: [PATCH 1/3] fix : add annocation cors --- .../server/MemberServiceApplication.java | 2 +- .../global/security/SecurityConfig.java | 26 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/java/gwangjang/server/MemberServiceApplication.java b/src/main/java/gwangjang/server/MemberServiceApplication.java index 8db3565..0f3e1ff 100644 --- a/src/main/java/gwangjang/server/MemberServiceApplication.java +++ b/src/main/java/gwangjang/server/MemberServiceApplication.java @@ -7,7 +7,7 @@ import org.springframework.data.jpa.repository.config.EnableJpaAuditing; import org.springframework.web.bind.annotation.CrossOrigin; -//@CrossOrigin("*") +@CrossOrigin("*") @EnableFeignClients @SpringBootApplication @EnableDiscoveryClient diff --git a/src/main/java/gwangjang/server/global/security/SecurityConfig.java b/src/main/java/gwangjang/server/global/security/SecurityConfig.java index fc62f32..dea3a00 100644 --- a/src/main/java/gwangjang/server/global/security/SecurityConfig.java +++ b/src/main/java/gwangjang/server/global/security/SecurityConfig.java @@ -70,18 +70,18 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { return http.build(); } - @Bean - public CorsConfigurationSource corsConfigurationSource() { - CorsConfiguration configuration = new CorsConfiguration(); - - configuration.addAllowedOriginPattern("*"); - configuration.addAllowedHeader("*"); - configuration.addAllowedMethod("*"); - configuration.setAllowCredentials(false); - - UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); - source.registerCorsConfiguration("/**", configuration); - return source; - } +// @Bean +// public CorsConfigurationSource corsConfigurationSource() { +// CorsConfiguration configuration = new CorsConfiguration(); +// +// configuration.addAllowedOriginPattern("*"); +// configuration.addAllowedHeader("*"); +// configuration.addAllowedMethod("*"); +// configuration.setAllowCredentials(false); +// +// UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); +// source.registerCorsConfiguration("/", configuration); +// return source; +// } } \ No newline at end of file From cfac9f33ab36b5fe1ddfe9a34785ebc011cf92df Mon Sep 17 00:00:00 2001 From: seungyeonnnnnni Date: Tue, 7 Nov 2023 17:01:04 +0900 Subject: [PATCH 2/3] fix : allow application/json and applicaiton/u-www/unencoded --- .../auth/presentation/AuthController.java | 14 +-- .../presentation/AuthControllerForJson.java | 108 ++++++++++++++++++ 2 files changed, 115 insertions(+), 7 deletions(-) create mode 100644 src/main/java/gwangjang/server/domain/auth/presentation/AuthControllerForJson.java diff --git a/src/main/java/gwangjang/server/domain/auth/presentation/AuthController.java b/src/main/java/gwangjang/server/domain/auth/presentation/AuthController.java index 1545301..c1cdfbb 100644 --- a/src/main/java/gwangjang/server/domain/auth/presentation/AuthController.java +++ b/src/main/java/gwangjang/server/domain/auth/presentation/AuthController.java @@ -24,8 +24,8 @@ @RestController @AllArgsConstructor //@CrossOrigin(origins = "*") -//@RequestMapping(value = "/auth",consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE) -@RequestMapping(value = "/auth") +@RequestMapping(value = "/auth",consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE) +//@RequestMapping(value = "/auth") @Slf4j public class AuthController { @@ -41,13 +41,13 @@ public class AuthController { @PostMapping("/signIn") - public ResponseEntity> signIn(@RequestBody LocalSignInRequest localSignInRequest) { + public ResponseEntity> signIn(LocalSignInRequest localSignInRequest) { return ResponseEntity.ok(SuccessResponse.create(SIGN_IN_SUCCESS.getMessage(), this.authService.localSignIn(localSignInRequest))); } @PostMapping("/signIn/{provider}") public ResponseEntity> socialSignIn(@PathVariable String provider, - @RequestBody SignInRequest signInRequest) { + SignInRequest signInRequest) { return ResponseEntity.ok(SuccessResponse.create(SIGN_IN_SUCCESS.getMessage(), this.authService.signIn(signInRequest.getToken(), provider))); } @@ -61,7 +61,7 @@ public ResponseEntity> socialSignUp(@PathVariabl } @PostMapping("/signUp") - public ResponseEntity> signUp(@RequestBody LocalSignUpRequest signUpRequest) { + public ResponseEntity> signUp( LocalSignUpRequest signUpRequest) { return ResponseEntity.ok(SuccessResponse.create(SIGN_UP_SUCCESS.getMessage(), this.signUpService.localSignUp(signUpRequest))); } @@ -80,7 +80,7 @@ public ResponseEntity> checkNickname(@Pat @PostMapping("/test/{provider}") public ResponseEntity> testLogin(@PathVariable String provider, - @RequestBody TestRequest testRequest){ + TestRequest testRequest){ return ResponseEntity.ok(SuccessResponse.create(SIGN_IN_SUCCESS.getMessage(), this.authService.testSignIn(testRequest.getSocialId(),provider))); } @@ -104,7 +104,7 @@ public ResponseEntity> sendEmailAuth(@PathVa } @PostMapping("/email") - public ResponseEntity> checkEmailAuth(@RequestBody CheckEmailRequest checkEmailRequest){ + public ResponseEntity> checkEmailAuth( CheckEmailRequest checkEmailRequest){ return ResponseEntity.ok(SuccessResponse.create(CHECK_EMAIL_AUTH_SUCCESS.getMessage(),checkEmailUserCase.checkEmailAuth(checkEmailRequest))); } diff --git a/src/main/java/gwangjang/server/domain/auth/presentation/AuthControllerForJson.java b/src/main/java/gwangjang/server/domain/auth/presentation/AuthControllerForJson.java new file mode 100644 index 0000000..8a1d1d3 --- /dev/null +++ b/src/main/java/gwangjang/server/domain/auth/presentation/AuthControllerForJson.java @@ -0,0 +1,108 @@ +package gwangjang.server.domain.auth.presentation; + +import gwangjang.server.domain.auth.application.dto.request.*; +import gwangjang.server.domain.auth.application.dto.response.CheckEmailResponse; +import gwangjang.server.domain.auth.application.dto.response.CheckNicknameResponse; +import gwangjang.server.domain.auth.application.dto.response.ReissueTokenResponse; +import gwangjang.server.domain.auth.application.dto.response.SignInResponse; +import gwangjang.server.domain.auth.application.service.*; +import gwangjang.server.domain.auth.application.service.kakao.KakaoTokenUserCase; +import gwangjang.server.global.response.SuccessResponse; +import gwangjang.server.global.security.dto.User; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.ResponseEntity; +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.web.bind.annotation.*; + +import static gwangjang.server.domain.auth.presentation.constant.AuthResponseMessage.*; + +@RestController +@AllArgsConstructor +//@CrossOrigin(origins = "*") +//@RequestMapping(value = "/auth",consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE) +@RequestMapping(value = "/auth") +@Slf4j +public class AuthControllerForJson { + + private final SignInUserCase authService; + + private final SignUpUserCase signUpService; + + private final ReissueTokenUserCase reissueTokenService; + private final CheckNicknameUserCase checkNicknameService; + private final KakaoTokenUserCase kakaoTokenUserCase; + private final CheckEmailUserCase checkEmailUserCase; + + + + @PostMapping("/signIn") + public ResponseEntity> signIn(@RequestBody LocalSignInRequest localSignInRequest) { + return ResponseEntity.ok(SuccessResponse.create(SIGN_IN_SUCCESS.getMessage(), this.authService.localSignIn(localSignInRequest))); + } + + @PostMapping("/signIn/{provider}") + public ResponseEntity> socialSignIn(@PathVariable String provider, + @RequestBody SignInRequest signInRequest) { + return ResponseEntity.ok(SuccessResponse.create(SIGN_IN_SUCCESS.getMessage(), this.authService.signIn(signInRequest.getToken(), provider))); + } + + + @PutMapping("/signUp/{provider}") + public ResponseEntity> socialSignUp(@PathVariable String provider, + @RequestHeader(value = "Authorization") String token, + SignUpRequest signUpRequest) { + token = (token != null && token.startsWith("Bearer ")) ? token.substring(7) : token; + return ResponseEntity.ok(SuccessResponse.create(SIGN_UP_SUCCESS.getMessage(), this.signUpService.signUp(token, signUpRequest))); + } + + @PostMapping("/signUp") + public ResponseEntity> signUp(@RequestBody LocalSignUpRequest signUpRequest) { + return ResponseEntity.ok(SuccessResponse.create(SIGN_UP_SUCCESS.getMessage(), this.signUpService.localSignUp(signUpRequest))); + } + + @GetMapping("/reissue") + public ResponseEntity> reissue(@RequestHeader(value = "RefreshToken") String token) { + ReissueTokenResponse reissueToken = reissueTokenService.reissueToken(token); + return ResponseEntity.ok(SuccessResponse.create(REISSUE_TOKEN_SUCCESS.getMessage(), reissueToken)); + } + + + @GetMapping("/nickname/{nickname}") + public ResponseEntity> checkNickname(@PathVariable String nickname){ + return ResponseEntity.ok(SuccessResponse.create(CHECK_NICKNAME_SUCCESS.getMessage(), checkNicknameService.checkNickname(nickname))); + } + + + @PostMapping("/test/{provider}") + public ResponseEntity> testLogin(@PathVariable String provider, + @RequestBody TestRequest testRequest){ + return ResponseEntity.ok(SuccessResponse.create(SIGN_IN_SUCCESS.getMessage(), this.authService.testSignIn(testRequest.getSocialId(),provider))); + } + + @PostMapping("/test/hi") + public ResponseEntity> test(@AuthenticationPrincipal User user){ + + log.info("/test/hi -> start "); + log.info(user.getEmail()); + return ResponseEntity.ok(SuccessResponse.create(SIGN_IN_SUCCESS.getMessage(),user.getEmail())); + } + + @GetMapping("/oauth/kakao") + public ResponseEntity> kakaoCallBack(@RequestParam String code){ + log.info("/oauth/kakao redirect success"); + return ResponseEntity.ok(SuccessResponse.create(KAKAO_CALL_BACK_SUCCESS.getMessage(),kakaoTokenUserCase.getAccessToken(code).getAccess_token())); + } + + @PostMapping("/email/{email}") + public ResponseEntity> sendEmailAuth(@PathVariable String email){ + return ResponseEntity.ok(SuccessResponse.create(CHECK_EMAIL_SUCCESS.getMessage(),checkEmailUserCase.requestEmail(email))); + } + + @PostMapping("/email") + public ResponseEntity> checkEmailAuth(@RequestBody CheckEmailRequest checkEmailRequest){ + return ResponseEntity.ok(SuccessResponse.create(CHECK_EMAIL_AUTH_SUCCESS.getMessage(),checkEmailUserCase.checkEmailAuth(checkEmailRequest))); + } + + +} \ No newline at end of file From 6fded69850c0213c875d835a2b22805b6dc4c7f1 Mon Sep 17 00:00:00 2001 From: seungyeonnnnnni Date: Tue, 7 Nov 2023 17:03:31 +0900 Subject: [PATCH 3/3] fix : not allow cors in memberservice --- src/main/java/gwangjang/server/MemberServiceApplication.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/gwangjang/server/MemberServiceApplication.java b/src/main/java/gwangjang/server/MemberServiceApplication.java index 0f3e1ff..8db3565 100644 --- a/src/main/java/gwangjang/server/MemberServiceApplication.java +++ b/src/main/java/gwangjang/server/MemberServiceApplication.java @@ -7,7 +7,7 @@ import org.springframework.data.jpa.repository.config.EnableJpaAuditing; import org.springframework.web.bind.annotation.CrossOrigin; -@CrossOrigin("*") +//@CrossOrigin("*") @EnableFeignClients @SpringBootApplication @EnableDiscoveryClient