문의 시, 사용하시는 개발환경과 디벨로퍼스 앱ID를 알려주세요.
앱 ID : 1085379
public String getAccessTokenFromKakaoDeploy(String code) {
KakaoTokenResponseDto kakaoTokenResponseDto = WebClient.create(KAUTH_TOKEN_URL_HOST)
.post()
.uri("/oauth/token")
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE)
.body(BodyInserters.fromFormData("grant_type", "authorization_code")
.with("client_id", clientId)
.with("client_secret", clientSecret)
.with("code", code)
.with("redirect_uri", "https://main--testtig.netlify.app/login/oauth2/code/kakao"))
.retrieve()
.onStatus(HttpStatusCode::is4xxClientError, clientResponse -> Mono.error(new BusinessExceptionHandler("Invalid Parameter " + clientResponse.toString(), ErrorCode.BAD_REQUEST_ERROR)))
.onStatus(HttpStatusCode::is5xxServerError, clientResponse -> Mono.error(new RuntimeException("500 Internal Server Error")))
.bodyToMono(KakaoTokenResponseDto.class)
.block();
log.info(" [Kakao Service] Access Token ------> {}", kakaoTokenResponseDto.getAccessToken());
log.info(" [Kakao Service] Refresh Token ------> {}", kakaoTokenResponseDto.getRefreshToken());
log.info(" [Kakao Service] Id Token ------> {}", kakaoTokenResponseDto.getIdToken());
log.info(" [Kakao Service] Scope ------> {}", kakaoTokenResponseDto.getScope());
return kakaoTokenResponseDto.getAccessToken();
}
위와 같은 코드로 카카오 서버에 액세스토큰 요청을 보냈습니다. 근데 다음과 같은 에러가 뜹니다.
java.lang.RuntimeException: 400 Invalid Parameter
at tig.server.kakao.service.KakaoService.lambda$getAccessTokenFromKakaoDeploy$4(KakaoService.java:76) ~[classes!/:0.0.1-SNAPSHOT]
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following site(s):
*__checkpoint ⇢ 400 BAD_REQUEST from POST https://kauth.kakao.com/oauth/token [DefaultWebClient]
clientId, clientSecret, code 모두 제대로 들어가는것은 확인 했습니다. redirect_uri 관련 문제일까요?