示例#1
0
文件: Base.php 项目: hughnguy/php
 function __construct($network_name, $config, $params = null)
 {
     if (!$params) {
         $this->params = Social_Auth::session()->get("sa_session.{$network_name}.network_params");
     } else {
         $this->params = $params;
     }
     $this->network_name = $network_name;
     $this->client = Social_Auth::session()->get("sa_session.{$network_name}.sa_client");
     $this->config = $config;
     $this->user = new Social_User();
     $this->user->network_name = $network_name;
     $this->init();
     Social_Logger::debug("Social_Protocol_Model_Base initialized for {$network_name} : ", serialize($this));
 }
示例#2
0
文件: Adapter.php 项目: hughnguy/php
 function login()
 {
     Social_Logger::info("###Social_Adapter::login( {$this->network_name} ) ");
     if (!$this->adapter) {
         throw new Social_Exception("Social_Adapter::login() cannot be used directly");
     }
     foreach (Social_Auth::$config["networks"] as $network => $params) {
         Social_Auth::session()->deleteByKey("sa_session.{$network}.sa_callback");
         Social_Auth::session()->deleteByKey("sa_session.{$network}.sa_client");
         Social_Auth::session()->deleteByKey("sa_session.{$network}.network_params");
     }
     $this->logout();
     $social_auth_base_url = Social_Auth::$config["base_url"];
     $this->params["sa_token"] = session_id();
     $this->params["sa_time"] = time();
     $this->params["sa_login"] = $social_auth_base_url . (strpos($social_auth_base_url, '?') ? '&' : '?') . "sa_login={$this->network_name}&sa_time={$this->params["sa_time"]}";
     $this->params["sa_login_finish"] = $social_auth_base_url . (strpos($social_auth_base_url, '?') ? '&' : '?') . "sa_login_finish={$this->network_name}";
     Social_Auth::session()->set("sa_session.{$this->network_name}.sa_callback", $this->params["sa_callback_url"]);
     Social_Auth::session()->set("sa_session.{$this->network_name}.sa_client", $this->params["sa_login_finish"]);
     Social_Auth::session()->set("sa_session.{$this->network_name}.network_params", $this->params);
     Social_Auth::session()->set("sa_config", Social_Auth::$config);
     Social_Logger::debug("Social_Adapter::login( {$this->network_name} ), redirecting sa_login url.");
     Social_Auth::redirect($this->params["sa_login"]);
 }
示例#3
0
 public static function prepare($network_name, $params = null)
 {
     Social_Logger::info("###Social_Auth::prepare( {$network_name} )", $params);
     if (!$params) {
         $params = Social_Auth::session()->get("sa_session.{$network_name}.network_params");
         Social_Logger::debug("Social_Auth::prepare( {$network_name} ), params will be fetched from session");
     }
     if (!$params) {
         $params = array();
         Social_Logger::info("Social_Auth::prepare( {$network_name} ), initialize new instance for params");
     }
     if (!isset($params["sa_callback_url"])) {
         $params["sa_callback_url"] = Social_Auth::getCurrentPage();
     }
     Social_Logger::debug("Social_Auth::prepare( {$network_name} ). SocialAuth callback url: " . $params["sa_callback_url"]);
     # instantiate a new IDProvider Adapter
     $network = new Social_Adapter();
     $network->factory($network_name, $params);
     return $network;
 }
示例#4
0
 /**
  * Make http request
  */
 function request($url, $method, $postfields = NULL, $auth_header = null)
 {
     Social_Logger::info("Enter OAuth1Client::request( {$method}, {$url} )");
     Social_Logger::debug("OAuth1Client::request(). dump post fields: ", serialize($postfields));
     $this->http_info = array();
     $ci = curl_init();
     /* Curl settings */
     curl_setopt($ci, CURLOPT_USERAGENT, $this->curl_useragent);
     curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this->curl_connect_time_out);
     curl_setopt($ci, CURLOPT_TIMEOUT, $this->curl_time_out);
     curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE);
     curl_setopt($ci, CURLOPT_HTTPHEADER, array('Expect:'));
     curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this->curl_ssl_verifypeer);
     curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader'));
     curl_setopt($ci, CURLOPT_HEADER, FALSE);
     if ($this->curl_proxy) {
         curl_setopt($ci, CURLOPT_PROXY, $this->curl_proxy);
     }
     switch ($method) {
         case 'POST':
             curl_setopt($ci, CURLOPT_POST, TRUE);
             if (!empty($postfields)) {
                 curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);
             }
             if (!empty($auth_header) && $this->curl_auth_header) {
                 curl_setopt($ci, CURLOPT_HTTPHEADER, array('Content-Type: application/atom+xml', $auth_header));
             }
             break;
         case 'DELETE':
             curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE');
             if (!empty($postfields)) {
                 $url = "{$url}?{$postfields}";
             }
     }
     curl_setopt($ci, CURLOPT_URL, $url);
     $response = curl_exec($ci);
     Social_Logger::debug("OAuth1Client::request(). dump request info: ", serialize(curl_getinfo($ci)));
     Social_Logger::debug("OAuth1Client::request(). dump request result: ", serialize($response));
     $this->http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE);
     $this->http_info = array_merge($this->http_info, curl_getinfo($ci));
     curl_close($ci);
     return $response;
 }
示例#5
0
 private function request($url, $params = false, $type = "GET")
 {
     Social_Logger::info("Enter OAuth2Client::request( {$url} )");
     Social_Logger::debug("OAuth2Client::request(). dump request params: ", serialize($params));
     if ($type == "GET") {
         $url = $url . (strpos($url, '?') ? '&' : '?') . http_build_query($params);
     }
     $this->http_info = array();
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_TIMEOUT, $this->curl_time_out);
     curl_setopt($ch, CURLOPT_USERAGENT, $this->curl_useragent);
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->curl_connect_time_out);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->curl_ssl_verifypeer);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $this->curl_header);
     if ($this->curl_proxy) {
         curl_setopt($ch, CURLOPT_PROXY, $this->curl_proxy);
     }
     if ($type == "POST") {
         curl_setopt($ch, CURLOPT_POST, 1);
         if ($params) {
             curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
         }
     }
     $response = curl_exec($ch);
     Social_Logger::debug("OAuth2Client::request(). dump request info: ", serialize(curl_getinfo($ch)));
     Social_Logger::debug("OAuth2Client::request(). dump request result: ", serialize($response));
     $this->http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     $this->http_info = array_merge($this->http_info, curl_getinfo($ch));
     curl_close($ch);
     return $response;
 }