You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.8 KiB

7 years ago
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. require_once APPPATH . "libraries/Social_login.php";
  4. class Social_login_naver extends Social_login {
  5. function __construct()
  6. {
  7. parent::__construct();
  8. $CI=&get_instance();
  9. $this->social_setting->client_id = $CI->site->config('social_naver_clientid');
  10. $this->social_setting->client_secret = $CI->site->config('social_naver_clientsecret');
  11. $this->social_setting->redirect_url = base_url("members/social-login/naver");
  12. $this->social_setting->authorize_url = "https://nid.naver.com/oauth2.0/authorize";
  13. $this->social_setting->token_url = "https://nid.naver.com/oauth2.0/token";
  14. $this->social_setting->info_url = "https://openapi.naver.com/v1/nid/me";
  15. $this->social_setting->token_request_post = FALSE;
  16. }
  17. /**
  18. * 사용자 프로필 받아오기
  19. */
  20. protected function _get_info( $access_token, $add_param="" )
  21. {
  22. $result = json_decode(parent::_get_info($access_token), TRUE);
  23. if( $result['resultcode'] == '00') {
  24. return $result;
  25. }
  26. else {
  27. return NULL;
  28. }
  29. }
  30. protected function _generate_profile($profile)
  31. {
  32. $return['provider'] = "naver";
  33. $return['id'] = $profile['response']['id'];
  34. $return['name'] = $profile['response']['nickname'];
  35. $return['profile'] = $profile['response']['profile_image'];
  36. $return['email'] = $profile['response']['email'];
  37. $return['gender'] = $profile['response']['gender'] == 'M' ? 'M' : ( $profile['response']['gender'] == 'F' ? 'F' : 'U' );
  38. $return['extra'] = json_encode($profile['response'], JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
  39. return $return;
  40. }
  41. }