Skip to content

Commit

Permalink
Merge pull request #97 from WE-ARE-RACCOONS/RAC-288
Browse files Browse the repository at this point in the history
  • Loading branch information
ywj9811 authored Jan 21, 2024
2 parents 112632e + 6816e96 commit cafdabb
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@

public interface SignInUseCase {
AuthUserResponse getUser(CodeRequest request);

AuthUserResponse getDevUser(CodeRequest codeRequest);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public class KakaoAccessTokenUseCase {
@Value("${app-id.kakao}")
private String APP_ID;
@Value("${kakao.redirect-uri}")
private String REDRECT_URI;
private String REDIRECT_URI;
@Value("${kakao.dev-redirect-uri}")
private String DEV_REDIRECT_URI;
@Value("${kakao.authorization-grant-type}")
private String AUTHORIZATION_GRANT_TYPE;
private final WebClient webClient;
Expand All @@ -47,11 +49,27 @@ public KakaoUserInfoResponse getAccessToken (CodeRequest codeRequest) {
}
}

public KakaoUserInfoResponse getDevAccessToken (CodeRequest codeRequest) {
MultiValueMap<String, String> requestBody = getDevRequestBody(codeRequest.code());
try {
KakaoTokenInfoResponse tokenInfoResponse = webClient.post()
.uri(KAKAO_TOKEN_URI)
.headers(h -> h.setContentType(MediaType.APPLICATION_FORM_URLENCODED))
.bodyValue(requestBody)
.retrieve()
.bodyToMono(KakaoTokenInfoResponse.class)
.block();
return getUserInfo(tokenInfoResponse.access_token());
} catch (WebClientResponseException ex) {
throw new KakaoCodeException();
}
}

private MultiValueMap<String, String> getRequestBody(String code) {
MultiValueMap<String, String> requestBody = new LinkedMultiValueMap<>();
requestBody.add("grant_type", AUTHORIZATION_GRANT_TYPE);
requestBody.add("client_id", APP_ID);
requestBody.add("redirect_uri", REDRECT_URI);
requestBody.add("redirect_uri", REDIRECT_URI);
requestBody.add("code", code);
return requestBody;
}
Expand All @@ -68,4 +86,13 @@ private KakaoUserInfoResponse getUserInfo(String accessToken) {
throw new KakaoException();
}
}

private MultiValueMap<String, String> getDevRequestBody(String code) {
MultiValueMap<String, String> requestBody = new LinkedMultiValueMap<>();
requestBody.add("grant_type", AUTHORIZATION_GRANT_TYPE);
requestBody.add("client_id", APP_ID);
requestBody.add("redirect_uri", DEV_REDIRECT_URI);
requestBody.add("code", code);
return requestBody;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,16 @@ public AuthUserResponse getUser(CodeRequest codeRequest) {
return AuthMapper.mapToAuthUser(socialId);
}
}

@Override
public AuthUserResponse getDevUser(CodeRequest codeRequest) {
KakaoUserInfoResponse userInfo = kakaoTokenUseCase.getDevAccessToken(codeRequest);
Long socialId = userInfo.id();
try {
User user = userGetService.bySocialId(socialId);
return AuthMapper.mapToAuthUser(user, socialId);
} catch (UserNotFoundException e) {
return AuthMapper.mapToAuthUser(socialId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ public ResponseDto<?> authLogin(@RequestBody @Valid CodeRequest request, @PathVa
return ResponseDto.create(AUTH_ALREADY.getCode(), SUCCESS_AUTH.getMessage(), jwtToken);
}

@PostMapping("/dev/login/{provider}")
@Operation(summary = "๊ฐœ๋ฐœ์šฉ ์†Œ์…œ ๋กœ๊ทธ์ธ", description = "ํšŒ์›์ธ ๊ฒฝ์šฐ JWT๋ฅผ, ํšŒ์›์ด ์•„๋‹Œ ๊ฒฝ์šฐ socialId๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค(ํšŒ์›๊ฐ€์ž…์€ ์ง„ํ–‰ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค).")
public ResponseDto<?> authDevLogin(@RequestBody @Valid CodeRequest request, @PathVariable Provider provider) {
SignInUseCase signInUseCase = selectOauth.selectSignIn(provider);
AuthUserResponse authUser = signInUseCase.getDevUser(request);
if (authUser.user() == null)
return ResponseDto.create(AUTH_NONE.getCode(), NOT_REGISTERED_USER.getMessage(), authUser);
JwtTokenResponse jwtToken = jwtUseCase.signIn(authUser.user());
return ResponseDto.create(AUTH_ALREADY.getCode(), SUCCESS_AUTH.getMessage(), jwtToken);
}

@PostMapping("/logout")
@Operation(summary = "๋กœ๊ทธ์•„์›ƒ", description = "ํ† ํฐ ๊ฐ™์ด ๋ณด๋‚ด์ฃผ์„ธ์š”")
public ResponseDto logout(@AuthenticationPrincipal User user) {
Expand Down

0 comments on commit cafdabb

Please sign in to comment.