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.

63 lines
2.2 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_facebook extends Social_login {
  5. function __construct()
  6. {
  7. parent::__construct();
  8. $CI =& get_instance();
  9. $this->social_setting->client_id = $CI->site->config('social_facebook_appid');
  10. $this->social_setting->client_secret = $CI->site->config('social_facebook_appsecret');
  11. $this->social_setting->redirect_url = base_url("members/social-login/facebook");
  12. $this->social_setting->authorize_url = "https://www.facebook.com/dialog/oauth";
  13. $this->social_setting->token_url = "https://graph.facebook.com/v2.4/oauth/access_token";
  14. $this->social_setting->info_url = "https://graph.facebook.com/v2.4/me";
  15. $this->social_setting->token_request_post = FALSE;
  16. }
  17. /**
  18. * oAuth 코드를 받아올때 필요한 패러미터를 가져온다.
  19. */
  20. protected function _get_authorize_param()
  21. {
  22. $param = parent::_get_authorize_param();
  23. $param['scope'] = "public_profile,email";
  24. return $param;
  25. }
  26. /**
  27. * 사용자 프로필 받아오기
  28. */
  29. protected function _get_info( $access_token, $add_param="" )
  30. {
  31. $fields = 'id,name,picture.width(1000).height(1000),link,email,verified,about,website,birthday,gender';
  32. $add_param = sprintf('?access_token=%s&fields=%s',$access_token, $fields);
  33. $result = json_decode(parent::_get_info($access_token, $add_param), TRUE);
  34. if( $result['id'] ) {
  35. return $result;
  36. }
  37. else {
  38. return NULL;
  39. }
  40. }
  41. protected function _generate_profile($profile)
  42. {
  43. $return['provider'] = "facebook";
  44. $return['id'] = $profile['id'];
  45. $return['name'] = $profile['name'];
  46. $return['profile'] = $profile['picture']['data']['url'];
  47. $return['email'] = $profile['email'];
  48. $return['gender'] = $profile['gender'] == 'male' ? 'M' : ( $profile['gender'] == 'female' ? 'F' : 'U' );
  49. $return['extra'] = json_encode($profile, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
  50. return $return;
  51. }
  52. }