Esempio n. 1
0
 private function request($url, $params = false, $type = "GET")
 {
     Hybrid_Logger::info("Enter OAuth2Client::request( {$url} )");
     Hybrid_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->api->curl_time_out);
     curl_setopt($ch, CURLOPT_USERAGENT, $this->api->curl_useragent);
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->api->curl_connect_time_out);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->api->curl_ssl_verifypeer);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $this->api->curl_header);
     if ($this->api->curl_proxy) {
         curl_setopt($ch, CURLOPT_PROXY, $this->api->curl_proxy);
     }
     if ($type == "POST") {
         curl_setopt($ch, CURLOPT_POST, 1);
         if ($params) {
             curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
         }
     }
     $response = curl_exec($ch);
     Hybrid_Logger::debug("OAuth2Client::request(). dump request info: ", serialize(curl_getinfo($ch)));
     Hybrid_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;
 }
Esempio n. 2
0
 private function authenticate($code)
 {
     $params = array("client_id" => $this->api->client_id, "client_secret" => $this->api->client_secret, "grant_type" => "authorization_code", "redirect_uri" => $this->api->redirect_uri, "code" => $code);
     $url = $this->api->token_url;
     $url = $url . (strpos($url, '?') ? '&' : '?') . http_build_query($params);
     $response = $this->api->api($url, 'POST');
     Hybrid_Logger::debug("authenticate with url: {$url}");
     if (!$response || !isset($response->access_token)) {
         throw new Exception("The Authorization Service has return: " . $response->error);
     }
     if (isset($response->access_token)) {
         $this->api->access_token = $response->access_token;
     }
     if (isset($response->refresh_token)) {
         $this->api->refresh_token = $response->refresh_token;
     }
     if (isset($response->expires_in)) {
         $this->api->access_token_expires_in = $response->expires_in;
     }
     // calculate when the access token expire
     if (isset($response->expires_in)) {
         $this->api->access_token_expires_at = time() + $response->expires_in;
     }
     return $response;
 }
Esempio n. 3
0
 /**
  * finish login step 
  */
 function loginFinish()
 {
     // in case we get error_reason=user_denied&error=access_denied
     if (isset($_REQUEST['error']) && $_REQUEST['error'] == "access_denied") {
         Hybrid_Logger::debug("QQ access_denied");
         throw new Exception("Authentification failed! The user denied your request.", 5);
     }
     if (!isset($_REQUEST['code']) || !isset($_REQUEST['state'])) {
         Hybrid_Logger::debug("QQ no code or state");
         throw new Exception("Authentification failed! The user denied your request.", 5);
     }
     $code = $_REQUEST['code'];
     $state = $_REQUEST['state'];
     // try to get the UID of the connected user from fb, should be > 0
     try {
         $access_token = $this->api->qq_callback();
         $openid = $this->api->get_openid();
         Hybrid_Logger::debug("Get QQ openid: {$openid}");
     } catch (Exception $e) {
         Hybrid_Logger::error("Authentification failed for {$this->providerId} ");
         Hybrid_Logger::error("Exception:" . $e->getMessage(), $e);
     }
     if (!$access_token || !$openid) {
         throw new Exception("Authentification failed! {$this->providerId} returned invalide access token or openid", 5);
     }
     // set user as logged in
     $this->setUserConnected();
     // store access token
     //$this->token( "access_token", $this->api->getAccessToken() );
 }
Esempio n. 4
0
 public function __construct($inc)
 {
     Hybrid_Logger::debug("Construct QQ Recorder");
     $this->error = new ErrorCase();
     //-------读取配置文件
     //$incFileContents = file(ROOT."comm/inc.php");
     //$incFileContents = $incFileContents[1];
     //$this->inc = json_decode($incFileContents);
     $this->inc = $inc;
     if (empty($this->inc)) {
         $this->error->showError("20001");
     }
     if (empty($_SESSION['QC_userData'])) {
         self::$data = array();
     } else {
         self::$data = $_SESSION['QC_userData'];
     }
 }
Esempio n. 5
0
 /**
  * common providers adapter constructor
  */
 function __construct($providerId, $config, $params = NULL)
 {
     # init the IDp adapter parameters, get them from the cache if possible
     if (!$params) {
         $this->params = Hybrid_Auth::storage()->get("hauth_session.{$providerId}.id_provider_params");
     } else {
         $this->params = $params;
     }
     // idp id
     $this->providerId = $providerId;
     // set HybridAuth endpoint for this provider
     $this->endpoint = Hybrid_Auth::storage()->get("hauth_session.{$providerId}.hauth_endpoint");
     // idp config
     $this->config = $config;
     // new user instance
     $this->user = new Hybrid_User();
     $this->user->providerId = $providerId;
     // initialize the current provider adapter
     $this->initialize();
     Hybrid_Logger::debug("Hybrid_Provider_Model::__construct( {$providerId} ) initialized. dump current adapter instance: ", serialize($this));
 }
Esempio n. 6
0
 /**
  * Setup an adapter for a given provider
  */
 public static function setup($providerId, $params = NULL)
 {
     Hybrid_Logger::debug("Enter Hybrid_Auth::setup( {$providerId} )", $params);
     if (!$params) {
         $params = Hybrid_Auth::storage()->get("hauth_session.{$providerId}.id_provider_params");
         Hybrid_Logger::debug("Hybrid_Auth::setup( {$providerId} ), no params given. Trying to get the sotred for this provider.", $params);
     }
     if (!$params) {
         $params = array();
         Hybrid_Logger::info("Hybrid_Auth::setup( {$providerId} ), no stored params found for this provider. Initialize a new one for new session");
     }
     if (!isset($params["hauth_return_to"])) {
         $params["hauth_return_to"] = Hybrid_Auth::getCurrentUrl();
     }
     Hybrid_Logger::debug("Hybrid_Auth::setup( {$providerId} ). HybridAuth Callback URL set to: ", $params["hauth_return_to"]);
     # instantiate a new IDProvider Adapter
     $provider = new Hybrid_Provider_Adapter();
     $provider->factory($providerId, $params);
     return $provider;
 }
Esempio n. 7
0
 /**
  * Hybrid_Provider_Adapter::login(), prepare the user session and the authentification request
  * for index.php
  */
 function login()
 {
     Hybrid_Logger::info("Enter Hybrid_Provider_Adapter::login( {$this->id} ) ");
     if (!$this->adapter) {
         throw new Exception("Hybrid_Provider_Adapter::login() should not directly used.");
     }
     // clear all unneeded params
     foreach (Hybrid_Auth::$config["providers"] as $idpid => $params) {
         Hybrid_Auth::storage()->delete("hauth_session.{$idpid}.hauth_return_to");
         Hybrid_Auth::storage()->delete("hauth_session.{$idpid}.hauth_endpoint");
         Hybrid_Auth::storage()->delete("hauth_session.{$idpid}.id_provider_params");
     }
     // make a fresh start
     $this->logout();
     # get hybridauth base url
     $HYBRID_AUTH_URL_BASE = Hybrid_Auth::$config["base_url"];
     # we make use of session_id() as storage hash to identify the current user
     # using session_regenerate_id() will be a problem, but ..
     $this->params["hauth_token"] = session_id();
     # set request timestamp
     $this->params["hauth_time"] = time();
     # for default HybridAuth endpoint url hauth_login_start_url
     # 	auth.start  required  the IDp ID
     # 	auth.time   optional  login request timestamp
     $this->params["login_start"] = $HYBRID_AUTH_URL_BASE . (strpos($HYBRID_AUTH_URL_BASE, '?') ? '&' : '?') . "hauth.start={$this->id}&hauth.time={$this->params["hauth_time"]}";
     # for default HybridAuth endpoint url hauth_login_done_url
     # 	auth.done   required  the IDp ID
     $this->params["login_done"] = $HYBRID_AUTH_URL_BASE . (strpos($HYBRID_AUTH_URL_BASE, '?') ? '&' : '?') . "hauth.done={$this->id}";
     Hybrid_Auth::storage()->set("hauth_session.{$this->id}.hauth_return_to", $this->params["hauth_return_to"]);
     Hybrid_Auth::storage()->set("hauth_session.{$this->id}.hauth_endpoint", $this->params["login_done"]);
     Hybrid_Auth::storage()->set("hauth_session.{$this->id}.id_provider_params", $this->params);
     // store config to be used by the end point
     $_SESSION["HA::CONFIG"] = serialize(Hybrid_Auth::$config);
     // move on
     Hybrid_Logger::debug("Hybrid_Provider_Adapter::login( {$this->id} ), redirect the user to login_start URL.", $this->params);
     Hybrid_Auth::redirect($this->params["login_start"]);
 }
Esempio n. 8
0
 /**
  * Hybrid_Provider_Adapter::login(), prepare the user session and the authentication request
  * for index.php
  * @return void
  * @throw Exception
  */
 function login()
 {
     Hybrid_Logger::info("Enter Hybrid_Provider_Adapter::login( {$this->id} ) ");
     if (!$this->adapter) {
         throw new Exception("Hybrid_Provider_Adapter::login() should not directly used.");
     }
     // clear all unneeded params
     foreach (Hybrid_Auth::$config["providers"] as $idpid => $params) {
         Hybrid_Auth::storage()->delete("hauth_session.{$idpid}.hauth_return_to");
         Hybrid_Auth::storage()->delete("hauth_session.{$idpid}.hauth_endpoint");
         Hybrid_Auth::storage()->delete("hauth_session.{$idpid}.id_provider_params");
     }
     // make a fresh start
     $this->logout();
     # get hybridauth base url
     if (empty(Hybrid_Auth::$config["base_url"])) {
         // the base url wasn't provide, so we must use the current
         // url (which makes sense actually)
         $url = empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off' ? 'http' : 'https';
         $url .= '://' . $_SERVER['HTTP_HOST'];
         $url .= $_SERVER['REQUEST_URI'];
         $HYBRID_AUTH_URL_BASE = $url;
     } else {
         $HYBRID_AUTH_URL_BASE = Hybrid_Auth::$config["base_url"];
     }
     // make sure params is array
     if (!is_array($this->params)) {
         $this->params = array();
     }
     # we make use of session_id() as storage hash to identify the current user
     # using session_regenerate_id() will be a problem, but ..
     $this->params["hauth_token"] = session_id();
     # set request timestamp
     $this->params["hauth_time"] = time();
     # for default HybridAuth endpoint url hauth_login_start_url
     # 	auth.start  required  the IDp ID
     # 	auth.time   optional  login request timestamp
     $this->params["login_start"] = $HYBRID_AUTH_URL_BASE . (strpos($HYBRID_AUTH_URL_BASE, '?') ? '&' : '?') . "hauth.start={$this->id}&hauth.time={$this->params["hauth_time"]}";
     # for default HybridAuth endpoint url hauth_login_done_url
     # 	auth.done   required  the IDp ID
     $this->params["login_done"] = $HYBRID_AUTH_URL_BASE . (strpos($HYBRID_AUTH_URL_BASE, '?') ? '&' : '?') . "hauth.done={$this->id}";
     if (isset($this->params["hauth_return_to"])) {
         Hybrid_Auth::storage()->set("hauth_session.{$this->id}.hauth_return_to", $this->params["hauth_return_to"]);
     }
     if (isset($this->params["login_done"])) {
         Hybrid_Auth::storage()->set("hauth_session.{$this->id}.hauth_endpoint", $this->params["login_done"]);
     }
     Hybrid_Auth::storage()->set("hauth_session.{$this->id}.id_provider_params", $this->params);
     // store config to be used by the end point
     Hybrid_Auth::storage()->config("CONFIG", Hybrid_Auth::$config);
     // move on
     Hybrid_Logger::debug("Hybrid_Provider_Adapter::login( {$this->id} ), redirect the user to login_start URL.");
     Hybrid_Auth::redirect($this->params["login_start"]);
 }
Esempio n. 9
0
 /** 
  * Make http request  
  */
 function request($url, $method, $postfields = NULL, $auth_header = NULL, $content_type = NULL)
 {
     Hybrid_Logger::info("Enter OAuth1Client::request( {$method}, {$url} )");
     Hybrid_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 ($content_type) {
         curl_setopt($ci, CURLOPT_HTTPHEADER, array('Expect:', "Content-Type: {$content_type}"));
     }
     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);
     if ($response === FALSE) {
         Hybrid_Logger::error("OAuth1Client::request(). curl_exec error: ", curl_error($ci));
     }
     Hybrid_Logger::debug("OAuth1Client::request(). dump request info: ", serialize(curl_getinfo($ci)));
     Hybrid_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;
 }
Esempio n. 10
0
 public function destroySession()
 {
     Hybrid_Logger::debug("Enter QC.class destroySession");
     $this->recorder->destroySession();
     //     	$cookie_name = "openapi.qzone.qq.com";
     //     	if (array_key_exists($cookie_name, $_COOKIE)) {
     //     		Hybrid_Logger::debug( "Enter QC.class delete cookie" );
     //     		setcookie($cookie_name, "", time() - 1);
     //     	}
     print_r($_COOKIE);
     if (isset($_COOKIE)) {
         $cookies = explode(';', $_COOKIE);
         foreach ($cookies as $cookie) {
             $parts = explode('=', $cookie);
             $name = trim($parts[0]);
             Hybrid_Logger::debug("http_cookie {$name}");
             //setcookie($name, '', time()-1000);
             //setcookie($name, '', time()-1000, '/');
         }
     }
     //     	$qzone_cookie = array('RK', 'pgv_pvi', 'pgv_si', 'pt2gguin','ptcz');
     //     	if (!empty($_COOKIE))
     //     	{
     //     		foreach ($_COOKIE as $name => $value)
     //     		{
     //     			if (in_array($name, $qzone_cookie))
     //     			{
     //     				Hybrid_Logger::debug( "destroy qzone_cookie {$name}" );
     //     				setcookie($name, $value, time() -1);
     //     			}
     //     		}
     //     	}
 }
 private function request($url, $params = false, $type = "GET")
 {
     $params = http_build_query($params, '', '&');
     Hybrid_Logger::info("Enter OAuth2Client::request( {$url} )");
     Hybrid_Logger::debug("OAuth2Client::request(). dump request params: ", $params);
     if ($type == "GET") {
         $url = $url . (strpos($url, '?') ? '&' : '?') . $params;
     }
     $this->http_info = array();
     $ch = curl_init();
     $headers = $this->curl_header;
     if ($type == "POST") {
         //$headers[] = 'Content-Type: application/x-www-form-urlencoded';
     }
     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_SSL_VERIFYHOST, $this->curl_ssl_verifyhost);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     curl_setopt($ch, CURLOPT_USERPWD, $this->client_id . ':' . $this->client_secret);
     // logging
     if ($this->curl_log !== null) {
         $fp = fopen($this->curl_log, 'a');
         curl_setopt($ch, CURLOPT_STDERR, $fp);
         curl_setopt($ch, CURLOPT_VERBOSE, 1);
     }
     if ($this->curl_proxy) {
         curl_setopt($ch, CURLOPT_PROXY, $this->curl_proxy);
     }
     if ($type == "POST") {
         curl_setopt($ch, CURLOPT_POST, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
     }
     $response = curl_exec($ch);
     if ($this->curl_log !== null) {
         fclose($fp);
     }
     if ($response === FALSE) {
         Hybrid_Logger::error("OAuth2Client::request(). curl_exec error: ", curl_error($ch));
     }
     Hybrid_Logger::debug("OAuth2Client::request(). dump request info: ", serialize(curl_getinfo($ch)));
     Hybrid_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;
 }
Esempio n. 12
0
 private function request($url, $params = false, $type = "GET")
 {
     Hybrid_Logger::info("Enter OAuth2Client::request( {$url} )");
     Hybrid_Logger::debug("OAuth2Client::request(). dump request params: ", serialize($params));
     if ($type == "GET") {
         $url = $url . "?" . http_build_query($params);
     }
     $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 ($type == "POST") {
         curl_setopt($ch, CURLOPT_POST, 1);
         if ($params) {
             curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
         }
     }
     $result = curl_exec($ch);
     $info = curl_getinfo($ch);
     curl_close($ch);
     Hybrid_Logger::debug("OAuth2Client::request(). dump request info: ", serialize($info));
     Hybrid_Logger::debug("OAuth2Client::request(). dump request result: ", serialize($result));
     return $result;
 }
Esempio n. 13
0
 private function request($url, $params = false, $type = "GET")
 {
     Hybrid_Logger::info("Enter OAuth2Client::request( {$url} )");
     Hybrid_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);
     $config = Yii::app()->getModule('hybridauth')->getConfig();
     if ($config['proxy']) {
         curl_setopt($ch, CURLOPT_PROXYTYPE, 'HTTPS');
         curl_setopt($ch, CURLOPT_PROXY, $config['proxy']['url']);
         curl_setopt($ch, CURLOPT_PROXYPORT, $config['proxy']['port']);
         if ($config['proxy']['user']) {
             curl_setopt($ch, CURLOPT_PROXYUSERPWD, $config['proxy']['user'] . ':' . $config['proxy']['password']);
         }
         //curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_NTLM);
     }
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->curl_ssl_verifypeer);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $this->curl_header);
     if ($type == "POST") {
         curl_setopt($ch, CURLOPT_POST, 1);
         if ($params) {
             curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
         }
     }
     $response = curl_exec($ch);
     Hybrid_Logger::debug("OAuth2Client::request(). dump request info: ", serialize(curl_getinfo($ch)));
     Hybrid_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;
 }
Esempio n. 14
0
 /** 
  * Make http request  
  */
 function request($url, $method, $postfields = NULL, $auth_header = null)
 {
     Hybrid_Logger::info("Enter OAuth1Client::request( {$method}, {$url} )");
     Hybrid_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);
     $config = Yii::app()->getModule('hybridauth')->getConfig();
     if ($config['proxy']) {
         curl_setopt($ch, CURLOPT_PROXYTYPE, 'HTTPS');
         curl_setopt($ch, CURLOPT_PROXY, $config['proxy']['url']);
         curl_setopt($ch, CURLOPT_PROXYPORT, $config['proxy']['port']);
         if ($config['proxy']['user']) {
             curl_setopt($ch, CURLOPT_PROXYUSERPWD, $config['proxy']['user'] . ':' . $config['proxy']['password']);
         }
         //curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_NTLM);
     }
     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);
     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);
     Hybrid_Logger::debug("OAuth1Client::request(). dump request info: ", serialize(curl_getinfo($ci)));
     Hybrid_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;
 }
Esempio n. 15
0
 /**
  * Call OU->UnitDetail
  *
  * @ignore
  * @param \SoapClient $ouClient Nastavený SoapClient
  * @param int $unitId
  * @param string $idLogin
  * @return \HybridAuth\SkautIS\Unit
  */
 protected function fetchUnitDetails(\SoapClient $ouClient, $unitId, $idLogin)
 {
     if (isset($this->unitDataCache[$unitId])) {
         if (!$this->unitDataCache[$unitId]) {
             return null;
         }
         return $this->unitDataCache[$unitId];
     }
     try {
         $unitDetailResult = $ouClient->UnitDetail(array("unitDetailInput" => array("ID_Login" => $idLogin, "ID" => $unitId)));
         \Hybrid_Logger::debug("Called SkautIS's OU->UnitDetail", $unitDetailResult);
     } catch (\Exception $e) {
         $this->unitDataCache[$unitId] = false;
         return null;
     }
     if ($unitDetailResult) {
         $unitObject = new Unit($unitDetailResult->UnitDetailResult);
         $this->unitDataCache[$unitId] = $unitObject;
         return $unitObject;
     }
     $this->unitDataCache[$unitId] = false;
     return null;
 }
Esempio n. 16
0
 /**
  * Hybrid_Provider_Adapter::login(), prepare the user session and the authentication request
  * for index.php
  * @return void
  * @throw Exception
  */
 function login()
 {
     Hybrid_Logger::info("Enter Hybrid_Provider_Adapter::login( {$this->id} ) ");
     if (!$this->adapter) {
         throw new Exception("Hybrid_Provider_Adapter::login() should not directly used.");
     }
     // clear all unneeded params
     foreach (Hybrid_Auth::$config["providers"] as $idpid => $params) {
         Hybrid_Auth::storage()->delete("hauth_session.{$idpid}.hauth_return_to");
         Hybrid_Auth::storage()->delete("hauth_session.{$idpid}.hauth_endpoint");
         Hybrid_Auth::storage()->delete("hauth_session.{$idpid}.id_provider_params");
     }
     // make a fresh start
     $this->logout();
     # get hybridauth base url
     if (empty(Hybrid_Auth::$config["base_url"])) {
         // the base url wasn't provide, so we must use the current
         // url (which makes sense actually)
         $url = empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off' ? 'http' : 'https';
         $url .= '://' . $_SERVER['HTTP_HOST'];
         $url .= $_SERVER['REQUEST_URI'];
         $HYBRID_AUTH_URL_BASE = $url;
     } else {
         $HYBRID_AUTH_URL_BASE = Hybrid_Auth::$config["base_url"];
     }
     // make sure params is array
     if (!is_array($this->params)) {
         $this->params = array();
     }
     # we make use of session_id() as storage hash to identify the current user
     # using session_regenerate_id() will be a problem, but ..
     $this->params["hauth_token"] = session_id();
     # set request timestamp
     $this->params["hauth_time"] = time();
     # for default HybridAuth endpoint url hauth_login_start_url
     # 	auth.start  required  the IDp ID
     # 	auth.time   optional  login request timestamp
     if (!isset($this->params["login_start"])) {
         $this->params["login_start"] = $HYBRID_AUTH_URL_BASE . (strpos($HYBRID_AUTH_URL_BASE, '?') ? '&' : '?') . "hauth.start={$this->id}&hauth.time={$this->params["hauth_time"]}";
     }
     # for default HybridAuth endpoint url hauth_login_done_url
     # 	auth.done   required  the IDp ID
     if (!isset($this->params["login_done"])) {
         $this->params["login_done"] = $HYBRID_AUTH_URL_BASE . (strpos($HYBRID_AUTH_URL_BASE, '?') ? '&' : '?') . "hauth.done={$this->id}";
     }
     # workaround to solve windows live authentication since microsoft disallowed redirect urls to contain any parameters
     # http://mywebsite.com/path_to_hybridauth/?hauth.done=Live will not work
     if ($this->id == "Live") {
         $this->params["login_done"] = $HYBRID_AUTH_URL_BASE . "live.php";
     }
     # Workaround to fix broken callback urls for the Facebook OAuth client
     if ($this->adapter->useSafeUrls) {
         $this->params['login_done'] = str_replace('hauth.done', 'hauth_done', $this->params['login_done']);
     }
     if (isset($this->params["hauth_return_to"])) {
         Hybrid_Auth::storage()->set("hauth_session.{$this->id}.hauth_return_to", $this->params["hauth_return_to"]);
     }
     if (isset($this->params["login_done"])) {
         Hybrid_Auth::storage()->set("hauth_session.{$this->id}.hauth_endpoint", $this->params["login_done"]);
     }
     Hybrid_Auth::storage()->set("hauth_session.{$this->id}.id_provider_params", $this->params);
     // store config to be used by the end point
     Hybrid_Auth::storage()->config("CONFIG", Hybrid_Auth::$config);
     // move on
     Hybrid_Logger::debug("Hybrid_Provider_Adapter::login( {$this->id} ), redirect the user to login_start URL.");
     // redirect
     if (empty($this->params["redirect_mode"])) {
         Hybrid_Auth::redirect($this->params["login_start"]);
     } else {
         Hybrid_Auth::redirect($this->params["login_start"], $this->params["redirect_mode"]);
     }
 }