diff --git a/app/library/OAuth.php b/app/library/OAuth.php deleted file mode 100644 index c08de76..0000000 --- a/app/library/OAuth.php +++ /dev/null @@ -1,103 +0,0 @@ - '/oauth/', - 'callback_url' => '/oauth/callback' - ); - - protected $_oauth; - - protected $_callbackName = 'callback'; - - public function __construct($config) - { - $config = $this->objectToArray($config->oauth); - - $this->_config = array_merge($this->_config, $config); - - $this->_oauth = new Opauth($this->_config, false); - } - - /** - * @return mixed|null|void - */ - public function perform() - { - $strategy = $this->dispatcher->getParam('strategy', null, false); - - if ($strategy == $this->_callbackName) { - return $this->getResponse(); - } - - $this->_oauth->run(); - exit; - } - - /** - * @return array|string - */ - public function getResponse() - { - $response = null; - switch($this->_oauth->env['callback_transport']) { - case 'session': - $response = $this->session->get('opauth'); - $this->session->remove('opauth'); - break; - case 'post': - $response = unserialize(base64_decode( $_POST['opauth'] )); - break; - case 'get': - $response = unserialize(base64_decode( $_GET['opauth'] )); - break; - } - - $ret = $this->_validate($response, $reason); - if ($ret === false) { - return $reason; - } - return $response; - } - - public function objectToArray($object) - { - if(!is_object($object) && !is_array($object)) - { - return $object; - } - if(is_object($object)) - { - $object = get_object_vars( $object ); - } - return array_map(array($this,"objectToArray"), $object ); - } - - protected function _validate($response, &$reason) - { - if (isset($response['auth']) && - isset($response['timestamp']) && - isset($response['signature'])) { - - $hash = sha1(print_r($response['auth'], true)); - - return $this->_oauth->validate($hash, $response['timestamp'], - $response['signature'], $reason); - } - - $reason = "Invalid auth response"; - return false; - } -} diff --git a/app/library/OAuth/Client.php b/app/library/OAuth/Client.php new file mode 100644 index 0000000..be703e8 --- /dev/null +++ b/app/library/OAuth/Client.php @@ -0,0 +1,59 @@ +_adapter = $adapter; + } + + public function getAuthorizationUrl() + { + return $this->_adapter->getAuthorizationUrl(); + } + + /** + * @param string $code + * @return UserDataInterface + */ + public function authenticate($code) + { + $this->_adapter->fetchAccessToken($code); + + return $this->getUserData(); + } + + /** + * @return UserDataInterface + */ + public function getUserData() + { + $data = $this->_adapter->getResourceData(); + return $this->_createUserData($data); + } + + protected function _createUserData(array $data) + { + $name = $this->_adapter->getProviderName(); + $class = "Httpcb\\OAuth\\UserData\\{$name}"; + return new $class($data); + } +}