-
[CIBOARD] 소셜로그인 네이버로그인이 '로그인에 실패하였습니다' 오류 해결PHP/codeigniter 2020. 9. 22. 13:07
다른 소셜로그인은 정상작동하는데
네이버로그인에서만 회원가입과 요청정보까지 정상적으로 받았음에도 (정보제공동의창 에서 동의를 했음에도)
'로그인에 실패하였습니다' 알럿이 뜰 때 해결방법입니다.
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;
이렇게 변경!
'PHP > codeigniter' 카테고리의 다른 글
CIBOARD SMTP 이메일 전송 수정사항(feat. gmail smtp) (0) 2020.08.27 CIBOARD3.03 smarteditor 이미지 업로드 에러시 수정사항 (0) 2020.08.11