Skip to content

Commit

Permalink
Merge pull request #10 from kusitms-28th-Meetup-E/feat/auth
Browse files Browse the repository at this point in the history
Feat/auth
  • Loading branch information
seungueonn authored Nov 7, 2023
2 parents 0a265c2 + 6fded69 commit a2c0ead
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -41,13 +41,13 @@ public class AuthController {


@PostMapping("/signIn")
public ResponseEntity<SuccessResponse<SignInResponse>> signIn(@RequestBody LocalSignInRequest localSignInRequest) {
public ResponseEntity<SuccessResponse<SignInResponse>> signIn(LocalSignInRequest localSignInRequest) {
return ResponseEntity.ok(SuccessResponse.create(SIGN_IN_SUCCESS.getMessage(), this.authService.localSignIn(localSignInRequest)));
}

@PostMapping("/signIn/{provider}")
public ResponseEntity<SuccessResponse<SignInResponse>> socialSignIn(@PathVariable String provider,
@RequestBody SignInRequest signInRequest) {
SignInRequest signInRequest) {
return ResponseEntity.ok(SuccessResponse.create(SIGN_IN_SUCCESS.getMessage(), this.authService.signIn(signInRequest.getToken(), provider)));
}

Expand All @@ -61,7 +61,7 @@ public ResponseEntity<SuccessResponse<SignInResponse>> socialSignUp(@PathVariabl
}

@PostMapping("/signUp")
public ResponseEntity<SuccessResponse<SignInResponse>> signUp(@RequestBody LocalSignUpRequest signUpRequest) {
public ResponseEntity<SuccessResponse<SignInResponse>> signUp( LocalSignUpRequest signUpRequest) {
return ResponseEntity.ok(SuccessResponse.create(SIGN_UP_SUCCESS.getMessage(), this.signUpService.localSignUp(signUpRequest)));
}

Expand All @@ -80,7 +80,7 @@ public ResponseEntity<SuccessResponse<CheckNicknameResponse>> checkNickname(@Pat

@PostMapping("/test/{provider}")
public ResponseEntity<SuccessResponse<SignInResponse>> testLogin(@PathVariable String provider,
@RequestBody TestRequest testRequest){
TestRequest testRequest){
return ResponseEntity.ok(SuccessResponse.create(SIGN_IN_SUCCESS.getMessage(), this.authService.testSignIn(testRequest.getSocialId(),provider)));
}

Expand All @@ -104,7 +104,7 @@ public ResponseEntity<SuccessResponse<CheckEmailResponse>> sendEmailAuth(@PathVa
}

@PostMapping("/email")
public ResponseEntity<SuccessResponse<CheckEmailResponse>> checkEmailAuth(@RequestBody CheckEmailRequest checkEmailRequest){
public ResponseEntity<SuccessResponse<CheckEmailResponse>> checkEmailAuth( CheckEmailRequest checkEmailRequest){
return ResponseEntity.ok(SuccessResponse.create(CHECK_EMAIL_AUTH_SUCCESS.getMessage(),checkEmailUserCase.checkEmailAuth(checkEmailRequest)));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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<SuccessResponse<SignInResponse>> signIn(@RequestBody LocalSignInRequest localSignInRequest) {
return ResponseEntity.ok(SuccessResponse.create(SIGN_IN_SUCCESS.getMessage(), this.authService.localSignIn(localSignInRequest)));
}

@PostMapping("/signIn/{provider}")
public ResponseEntity<SuccessResponse<SignInResponse>> 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<SuccessResponse<SignInResponse>> 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<SuccessResponse<SignInResponse>> signUp(@RequestBody LocalSignUpRequest signUpRequest) {
return ResponseEntity.ok(SuccessResponse.create(SIGN_UP_SUCCESS.getMessage(), this.signUpService.localSignUp(signUpRequest)));
}

@GetMapping("/reissue")
public ResponseEntity<SuccessResponse<ReissueTokenResponse>> 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<SuccessResponse<CheckNicknameResponse>> checkNickname(@PathVariable String nickname){
return ResponseEntity.ok(SuccessResponse.create(CHECK_NICKNAME_SUCCESS.getMessage(), checkNicknameService.checkNickname(nickname)));
}


@PostMapping("/test/{provider}")
public ResponseEntity<SuccessResponse<SignInResponse>> 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<SuccessResponse<String>> 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<SuccessResponse<String>> 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<SuccessResponse<CheckEmailResponse>> sendEmailAuth(@PathVariable String email){
return ResponseEntity.ok(SuccessResponse.create(CHECK_EMAIL_SUCCESS.getMessage(),checkEmailUserCase.requestEmail(email)));
}

@PostMapping("/email")
public ResponseEntity<SuccessResponse<CheckEmailResponse>> checkEmailAuth(@RequestBody CheckEmailRequest checkEmailRequest){
return ResponseEntity.ok(SuccessResponse.create(CHECK_EMAIL_AUTH_SUCCESS.getMessage(),checkEmailUserCase.checkEmailAuth(checkEmailRequest)));
}


}
26 changes: 13 additions & 13 deletions src/main/java/gwangjang/server/global/security/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
// }

}

0 comments on commit a2c0ead

Please sign in to comment.