Skip to content

Commit

Permalink
Merge pull request #50 from FlouD-2024/auth
Browse files Browse the repository at this point in the history
Refactor: modify kakao login api
  • Loading branch information
SeongJoon-K authored Mar 12, 2024
2 parents 2615ebb + ce283e2 commit cdf95cc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
12 changes: 6 additions & 6 deletions src/main/java/floud/demo/controller/AuthController.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ public RedirectView successGoogleLogin(@RequestParam("code") String code) {
public RedirectView redirectToGoogle() {
return authService.redirectToGoogle();
}

@GetMapping("/callback/kakao")
public ApiResponse<?> successKakaooLogin(@RequestParam("code") String code) {
return authService.getKakaoAccessToken(code);
}

@GetMapping("/kakao/login")
public RedirectView redirectToKakao() {
return authService.redirectToKakao();
}


@GetMapping("/callback/kakao")
public RedirectView successKakaooLogin(@RequestParam("code") String code) {
return authService.getKakaoAccessToken(code);
}

@GetMapping("/redirect")
public RedirectView redirectWithTokens(@RequestParam("access_token") String accessToken,
@RequestParam("refresh_token") String refreshToken) {
Expand Down
23 changes: 16 additions & 7 deletions src/main/java/floud/demo/service/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public RedirectView redirectToKakao() {
* 카카오 로그인시 id_token 발급하는 메소드
*/

public ApiResponse<?> getKakaoAccessToken(String code) {
public RedirectView getKakaoAccessToken(String code) {
RestTemplate restTemplate = new RestTemplate();

HttpHeaders headers = new HttpHeaders();
Expand Down Expand Up @@ -182,16 +182,25 @@ public ApiResponse<?> getKakaoAccessToken(String code) {
UsersResponseDto userInfo = getUserInfo(id_token);
saveRefreshToken(userInfo.getUsers_id(),refreshToken);

return ApiResponse.success(Success.GET_KAKAO_ACCESS_TOKEN_SUCCESS, TokenResponseDto.builder()
.id_token(id_token)
.refresh_token(refreshToken)
.build());
String redirectUrl = "http://localhost:3000/redirect";
redirectUrl += "?access_token=" + id_token + "&refresh_token=" + refreshToken;

// RedirectView를 사용하여 리다이렉션 수행
RedirectView redirectView = new RedirectView();
redirectView.setUrl(redirectUrl);

return redirectView;

// return ApiResponse.success(Success.GET_KAKAO_ACCESS_TOKEN_SUCCESS, TokenResponseDto.builder()
// .id_token(id_token)
// .refresh_token(refreshToken)
// .build());
} else {
return ApiResponse.failure(Error.ACCESS_TOKEN_NOT_FOUND);
return null;
}
} catch (Exception e) {
e.printStackTrace();
return ApiResponse.failure(e);
throw new IllegalArgumentException();
}
}

Expand Down

0 comments on commit cdf95cc

Please sign in to comment.