안녕하세요
카카오 로그인 기능을 사용하고자 테스트 중인데요 계속 invalid_client 에러가 발생되네요.
POST /oauth/token HTTP/1.1
Host: kauth.kakao.com
Content-type: application/x-www-form-urlencoded;charset=utf-8
사용자의 code를 사용해서 토큰을 받아오는 부분에서 리턴값에
WWW-Authenticate: Bearer realm=“oauth”, error=“invalid_client”, error_description="Bad client credentials"
이와 같은 오류가 발생됩니다.
그래서 혹시나 다른 환경에서도 같은 오류가 발생될까 궁금해 동일한 인자값으로 리눅스하고 웹(https://resttesttest.com/)에서 테스트 했는데 이때는 오류가 안나고 정상적으로 처리가 됐습니다.
테스트하면서 사용한 php 코드는 다음과 같습니다.
$data = [
‘client_id’ => $this->client_id,
‘redirect_uri’ => $this->login_url,
‘code’ => $code,
‘grant_type’ => ‘authorization_code’,
];
$url = ‘https://kauth.kakao.com/oauth/token’;
$header[] = ‘Content-Type: application/x-www-form-urlencoded; charset=utf-8’;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec ($ch);
php curl 을 사용할때 기존하고 다른방식의 세팅이 필요한거 같은데 어떻게 처리하면 좋을까요?
php curl 샘플 예시 같은게 있으면 좋겠습니다 ㅡㅜ