public function __construct($uri, $email, $password, $consumer_key, $consumer_secret, $oauth_realm, $cookieJarFile = './OX3_Api_CookieJar.txt', $sso = array(), $proxy = array())
 {
     parent::__construct($uri);
     $aUrl = parse_url($uri);
     if (empty($sso)) {
         $sso = array('siteUrl' => 'https://sso.openx.com/api/index/initiate', 'requestTokenUrl' => 'https://sso.openx.com/api/index/initiate', 'accessTokenUrl' => 'https://sso.openx.com/api/index/token', 'authorizeUrl' => 'https://sso.openx.com/login/login', 'loginUrl' => 'https://sso.openx.com/login/process');
     }
     // Set the proxy['adapter'] if $proxy config was passed in
     if (!empty($proxy)) {
         $proxy['adapter'] = 'Zend_Http_Client_Adapter_Proxy';
     }
     // Initilize the cookie jar, from the $cookieJarFile if present
     $client = self::getHttpClient();
     $cookieJar = false;
     if (is_readable($cookieJarFile)) {
         $cookieJar = @unserialize(file_get_contents($cookieJarFile));
     }
     if (!$cookieJar instanceof Zend_Http_CookieJar) {
         $cookieJar = new Zend_Http_CookieJar();
     }
     $client->setCookieJar($cookieJar);
     $client->setConfig($proxy);
     $result = $this->put('/a/session/validate');
     // See if the openx3_access_token is still valid...
     if ($result->isError()) {
         // Get Request Token
         $config = array('siteUrl' => $sso['siteUrl'], 'requestTokenUrl' => $sso['requestTokenUrl'], 'accessTokenUrl' => $sso['accessTokenUrl'], 'authorizeUrl' => $sso['authorizeUrl'], 'consumerKey' => $consumer_key, 'consumerSecret' => $consumer_secret, 'realm' => $oauth_realm);
         $oAuth = new OX3_Oauth_Consumer($config);
         $requestToken = $oAuth->getRequestToken();
         // Authenticate to SSO
         $loginClient = new Zend_Http_Client($sso['loginUrl']);
         $loginClient->setCookieJar();
         $loginClient->setConfig($proxy);
         $loginClient->setParameterPost(array('email' => $email, 'password' => $password, 'oauth_token' => $requestToken->getToken()));
         $loginClient->request(Zend_Http_Client::POST);
         $loginBody = $loginClient->getLastResponse()->getBody();
         // Parse response, sucessful headless logins will return oob?oauth_token=<token>&oauth_verifier=<verifier> as the body
         if (substr($loginBody, 0, 4) == 'oob?') {
             $vars = array();
             @parse_str(substr($loginBody, 4), $vars);
             if (empty($vars['oauth_token'])) {
                 throw new Exception('Error parsing SSO login response');
             }
             // Swap the (authorized) request token for an access token:
             $accessToken = $oAuth->getAccessToken($vars, $requestToken)->getToken();
             $client->setCookie(new Zend_Http_Cookie('openx3_access_token', $accessToken, $aUrl['host']));
             $result = $this->put('/a/session/validate');
             if ($result->isSuccessful()) {
                 file_put_contents($cookieJarFile, serialize($client->getCookieJar()), LOCK_EX);
                 chmod($cookieJarFile, 0666);
             }
         } else {
             throw new Exception('SSO Authentication error');
         }
     }
 }
Exemplo n.º 2
0
 public function __construct($serviceUrl = null)
 {
     if (is_null($serviceUrl)) {
         $serviceUrl = Zend_Registry::get('config')->service->users->url;
         if (!$serviceUrl) {
             throw new Kwf_Exception("'service.users.url' not defined in config (usually defined in KWF config)");
         }
     }
     parent::__construct($serviceUrl);
 }
Exemplo n.º 3
0
 public function __construct($type)
 {
     $this->_type = $type;
     $app = $GLOBALS['application']->getOption('app');
     $message_config = $app['messages'][$type];
     $server = $message_config['server'];
     $context = $message_config['context'];
     unset($message_config['server']);
     unset($message_config['context']);
     $this->_messages = new StdClass();
     foreach ($message_config as $key => $method) {
         $key = str_replace(' ', '', ucwords(str_replace('_', ' ', $key)));
         $this->_messages->{$key} = $context . $method;
     }
     Zend_Rest_Client::__construct($server);
     $this->getHttpClient()->setHeaders('Accept-Encoding', 'plain');
 }
Exemplo n.º 4
0
 /**
  * @param string $ps_url The url to connect to
  * @param array $ps_options An array of options:
  *		timeout = the number of seconds to wait for a response before throwing an exception. Default is 30 seconds.
  */
 public function __construct($ps_uri = null, $pa_options = null)
 {
     self::getHttpClient()->setCookieJar(true);
     self::getHttpClient()->setConfig(array("timeout" => isset($pa_options['timeout']) && (int) $pa_options['timeout'] > 0 ? (int) $pa_options['timeout'] : 30));
     parent::__construct($ps_uri);
 }