코드이그나이터 기반 PHP 오픈소스 게시판 : 씨아이보드

소셜로그인 네이버로그인 안될때 해결방법

  • 플라이이글스
  • 0
  • 2,739
  • 글주소
  • 09-22

다른 소셜로그인은 정상작동하는데


네이버로그인에서만 회원가입과 요청정보까지 정상적으로 받았음에도 (정보제공동의창 에서 동의를 했음에도)


'로그인에 실패하였습니다' 알럿이 뜰 때 해결방법입니다.


application/controller/social.php 350줄 부근 

function naver_login() 함수 안에

if($this->session->userdata('naver_access_token')) 이 if문 안에

  $url = 'https://apis.naver.com/nidlogin/nid/getUserProfile.xml';


$ch = curl_init();

curl_setopt ($ch, CURLOPT_URL, $url);

curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);

curl_setopt ($ch, CURLOPT_SSLVERSION, 1);

curl_setopt ($ch, CURLOPT_HEADER, 0);

curl_setopt ($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $this->session->userdata('naver_access_token')));

curl_setopt ($ch, CURLOPT_POST, 0);

curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);

curl_setopt ($ch, CURLOPT_TIMEOUT, 30);

curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

$result = curl_exec($ch);

curl_close($ch);


$xml = simplexml_load_string($result);


$naver_id = (string) $xml->response->enc_id;

$email = (string) $xml->response->email;

$nickname = (string) $xml->response->nickname;

$profile_image = (string) $xml->response->profile_image;

$age = (string) $xml->response->age;

$gender = (string) $xml->response->gender;

$id = (string) $xml->response->id;

$name = (string) $xml->response->name;

$birthday = (string) $xml->response->birthday;


이부분을

$url = 'https://openapi.naver.com/v1/nid/me';


$ch = curl_init();

curl_setopt ($ch, CURLOPT_URL, $url);

curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);

curl_setopt ($ch, CURLOPT_SSLVERSION, 1);

curl_setopt ($ch, CURLOPT_HEADER, 0);

curl_setopt ($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $this->session->userdata('naver_access_token')));

curl_setopt ($ch, CURLOPT_POST, 0);

curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);

curl_setopt ($ch, CURLOPT_TIMEOUT, 30);

curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

$result = curl_exec($ch);

curl_close($ch);


$json = json_decode($result);


$naver_id = (string) $json->response->id;

$email = (string) $json->response->email;

$nickname = (string) $json->response->nickname;

$profile_image = (string) $json->response->profile_image;

$age = (string) $json->response->age;

$gender = (string) $json->response->gender;

$id = (string) $json->response->id;

$name = (string) $json->response->name;

$birthday = (string) $json->response->birthday;


이렇게 바꿔주시면 정상작동합니다.