org.springframework.web.client.HttpClientErrorException$Unauthorized: 401 Unauthorized: [no body]
해당 에러가 뜨는데 확인 가능할까요?
앱 ID는 975229 입니다.
@Getter
@AllArgsConstructor
public class OAuthRequest {
private String url;
private LinkedMultiValueMap<String, String> map;
}
public OAuthRequest getRequest(String code, String provider) {
LinkedMultiValueMap<String, String> map = new LinkedMultiValueMap<>();
map.add("grant_type", "authorization_code");
map.add("client_id", kakaoInfo.getKakaoClientId());
map.add("redirect_uri", baseUrl + kakaoInfo.getKakaoRedirect());
map.add("code", code);
return new OAuthRequest(kakaoInfo.getKakaoTokenUrl(), map);
}
public AccessToken getAccessToken(String code, String provider) {
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
OAuthRequest oAuthRequest = oAuthRequestFactory.getRequest(code, provider);
HttpEntity<LinkedMultiValueMap<String, String>> request = new HttpEntity<>(oAuthRequest.getMap(), httpHeaders);
ResponseEntity<String> response = restTemplate.postForEntity(oAuthRequest.getUrl(), request, String.class);
try {
if (response.getStatusCode() == HttpStatus.OK) {
return gson.fromJson(response.getBody(), AccessToken.class);
}
} catch (Exception e) {
throw new RuntimeException();
}
throw new RuntimeException();
}