Skip to content

Commit

Permalink
merge: 로그인 redirect url 요청값 추가 #93
Browse files Browse the repository at this point in the history
[CHORE] 로그인 redirect url 요청값 추가 #93
  • Loading branch information
sjk4618 authored Jan 20, 2025
2 parents 1d0f43a + 6c6b6ec commit 2236758
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public LoginSuccessRes login(
final KakaoUserDto kakaoUserInfo;

if (loginReq.socialType().equals(SocialType.KAKAO)) {
kakaoUserInfo = kakaoSocialService.getKakaoUserInfo(authorizationCode);
kakaoUserInfo = kakaoSocialService.getKakaoUserInfo(authorizationCode, loginReq.redirectUri());
} else {
throw new UserBadRequestException(UserErrorCode.USER_SOCIAL_TYPE_NOT_FOUND); //todo: exception 변경
}
Expand Down
3 changes: 2 additions & 1 deletion cakey-auth/src/main/java/com/cakey/client/dto/LoginReq.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.cakey.client.SocialType;

public record LoginReq(
SocialType socialType
SocialType socialType,
String redirectUri
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,32 @@ public class KakaoSocialService {
private final KakaoAuthApiClient kakaoAuthApiClient;

private static final String AUTH_CODE = "authorization_code";
private static final String REDIRECT_URI = "http://localhost:5173/kakao/redirection";

@Value("${kakao.clientId}")
private String clientId;

public KakaoUserDto getKakaoUserInfo(final String authorizationCode) {
public KakaoUserDto getKakaoUserInfo(final String authorizationCode, final String redirectUri) {
String kakaoAccessToken;
try {
// 인가 코드로 카카오 Access Token 받아오기
kakaoAccessToken = getOAuth2Authentication(authorizationCode);
kakaoAccessToken = getOAuth2Authentication(authorizationCode, redirectUri);
} catch (FeignException e) {
throw new RuntimeException("authentication code expired");
}

String contentType = MediaType.APPLICATION_FORM_URLENCODED.toString();
final String contentType = MediaType.APPLICATION_FORM_URLENCODED.toString();
// Access Token으로 유저 정보 불러오기
return getUserInfo(kakaoAccessToken, contentType);
}

private String getOAuth2Authentication(
final String authorizationCode
final String authorizationCode,
final String redirectUri
) {
KakaoAccessTokenRes response = kakaoAuthApiClient.getOAuth2AccessToken(
final KakaoAccessTokenRes response = kakaoAuthApiClient.getOAuth2AccessToken(
AUTH_CODE,
clientId,
REDIRECT_URI,
redirectUri,
authorizationCode
);
return response.accessToken();
Expand Down

0 comments on commit 2236758

Please sign in to comment.