앱 id : 1031481
@Override
public String requestAccessToken(OAuthLoginParams params) {
String url = authUrl + "/oauth/token";
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
MultiValueMap<String, String> body = params.makeBody();
body.add("grant_type", GRANT_TYPE);
body.add("client_id", clientId);
body.add("redirect_uri", "http://localhost:3000/login/kakao");
HttpEntity<?> request = new HttpEntity<>(body, httpHeaders);
KakaoTokens response = restTemplate.postForObject(url, request, KakaoTokens.class);
assert response != null;
return response.getAccessToken();
}
org.springframework.web.client.HttpClientErrorException$Unauthorized: 401 Unauthorized: [no body]
라는 에러가 나고 있습니다
바디를 찍어보면 정상적으로 값이 들어와있는데 no body 라는 문구가 나와서 뭐가 문제인지 모르겠어요
client_id 도 몇 번이나 확인했는데 코드의 문제인지 어떤게 문제일까요?
tim.l
2
try {
KakaoTokens response = restTemplate.postForObject(url, request, KakaoTokens.class);
assert response != null;
return response.getAccessToken();
} catch(HttpStatusCodeException e) {
return ResponseEntity.status(e.getRawStatusCode()).headers(e.getResponseHeaders())
.body(e.getResponseBodyAsString());
}
상세 에러 메시지는 에러 Body로 전달됩니다. 확인 부탁드려요.
참고 . https://www.baeldung.com/spring-rest-template-error-handling
10_04
3
[2024-05-20 12:16:48:11869] ERROR 18956 — [nio-8080-exec-1] c.s.p.oauth.request.KakaoApiClient : Error requesting access token: status code = 401 UNAUTHORIZED, response headers = [Date:“Mon, 20 May 2024 03:16:49 GMT”, Content-Type:“application/json;charset=utf-8”, Transfer-Encoding:“chunked”, Connection:“keep-alive”, Cache-Control:“no-store”, Pragma:“no-cache”, WWW-Authenticate:“Bearer realm=“oauth”, error=“invalid_client”, error_description=“Bad client credentials””, X-XSS-Protection:“1; mode=block”, X-Frame-Options:“DENY”, X-Content-Type-Options:“nosniff”, Access-Control-Allow-Origin:“*”, Access-Control-Allow-Methods:“GET, POST, OPTIONS”, Access-Control-Allow-Headers:“Authorization, KA, Origin, X-Requested-With, Content-Type, Accept”], response body =
로그 찍어봤는데
error=“invalid_client”, error_description=“Bad client credentials”
client_id 문제일까요? rest_api 에 써져있는걸 그대로 넣었는데 이런 에러가 납니다
application-oauth.yml
oauth:
kakao:
client-id: “설정한 아이디”
url:
auth: https://kauth.kakao.com
api: https://kapi.kakao.com
application.yml
spring:
profiles:
include: oauth
tim.l
4
Bad client credentials 에러가 발생했다면, 아래 내용 참고해주세요.
KOE010 (Bad client credentials) 에러가 발생할 때