문의 시, 사용하시는 개발환경과 디벨로퍼스 앱ID를 알려주세요.
app id : 983681
jdk : correto 17
지난 게시글에 안내되어있는 client secret, content type 관련해 모두 수정했음에도 같은 오류가 반복됩니다. 확인 부탁드립니다.
{“error”:“invalid_client”,“error_description”:“Bad client credentials”,“error_code”:“KOE010”}
public class KakaoTokenUserCase {
@Value("${app-id.kakao}")
private String appId;
private final WebClient webClient;
private static String TOKEN_URI = "https://kauth.kakao.com/oauth/token";
@Value("${kakao.client.redirect-uri}")
private static String REDIRECT_URI;
private static String GRANT_TYPE = "authorization_code";
@Value("${kakao.client.id}")
private static String CLIENT_ID;
@Value("${kakao.client.secret}")
private static String CLIENT_Secret ;
public KakaoAuthTokenResponse getAccessToken(String authToken) {
//요청 param (body)
MultiValueMap<String , String> params = new LinkedMultiValueMap<>();
params.add("grant_type", GRANT_TYPE);
params.add("client_id",CLIENT_ID );
params.add("redirect_uri",REDIRECT_URI);
params.add("code", authToken);
params.add("client_secret", CLIENT_Secret);
WebClient webClient = WebClient.create(TOKEN_URI);
// baseURL 뒤에 붙일 파라미터들 넣기
String res = webClient.post()
.uri(TOKEN_URI)
.body(BodyInserters.fromFormData(params))
.header("Content-type","application/x-www-form-urlencoded;charset=utf-8" )
.retrieve()
.onStatus(HttpStatusCode::is4xxClientError, response -> response.bodyToMono(String.class)
.map(body -> new RuntimeException(body)))
.onStatus(HttpStatusCode::is5xxServerError, response -> Mono.error(new InternalServerErrorException("Kakao Internal Server Error ")))
.bodyToMono(String.class)
.block();
//json형태로 변환
ObjectMapper objectMapper = new ObjectMapper();
KakaoAuthTokenResponse KakaoAuthTokenResponse = null;
try {
KakaoAuthTokenResponse = objectMapper.readValue(res, KakaoAuthTokenResponse.class);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
log.info("please return kakaoAuthTokenResponse -> {}",KakaoAuthTokenResponse.getAccess_token());
return KakaoAuthTokenResponse;
}
}