From 87186d73b7d3b04cb9bd568eb5a203a4a838a663 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Tue, 12 Feb 2013 16:01:02 +0000 Subject: [PATCH] Removed old client code which can be now be found at lncd/oauth2-client --- src/OAuth2/Client/IDP.php | 230 --------------------- src/OAuth2/Client/Provider.php | 19 -- src/OAuth2/Client/Provider/Blooie.php | 42 ---- src/OAuth2/Client/Provider/Facebook.php | 49 ----- src/OAuth2/Client/Provider/Foursquare.php | 45 ---- src/OAuth2/Client/Provider/Github.php | 43 ---- src/OAuth2/Client/Provider/Google.php | 84 -------- src/OAuth2/Client/Provider/Instagram.php | 48 ----- src/OAuth2/Client/Provider/Mailchimp.php | 36 ---- src/OAuth2/Client/Provider/Mailru.php | 73 ------- src/OAuth2/Client/Provider/Paypal.php | 59 ------ src/OAuth2/Client/Provider/Soundcloud.php | 51 ----- src/OAuth2/Client/Provider/Vkontakte.php | 54 ----- src/OAuth2/Client/Provider/Windowslive.php | 60 ------ src/OAuth2/Client/Provider/Yandex.php | 115 ----------- src/OAuth2/Client/Token.php | 46 ----- src/OAuth2/Client/Token/Access.php | 79 ------- src/OAuth2/Client/Token/Authorize.php | 55 ----- 18 files changed, 1188 deletions(-) delete mode 100644 src/OAuth2/Client/IDP.php delete mode 100755 src/OAuth2/Client/Provider.php delete mode 100755 src/OAuth2/Client/Provider/Blooie.php delete mode 100755 src/OAuth2/Client/Provider/Facebook.php delete mode 100755 src/OAuth2/Client/Provider/Foursquare.php delete mode 100755 src/OAuth2/Client/Provider/Github.php delete mode 100755 src/OAuth2/Client/Provider/Google.php delete mode 100755 src/OAuth2/Client/Provider/Instagram.php delete mode 100755 src/OAuth2/Client/Provider/Mailchimp.php delete mode 100755 src/OAuth2/Client/Provider/Mailru.php delete mode 100755 src/OAuth2/Client/Provider/Paypal.php delete mode 100755 src/OAuth2/Client/Provider/Soundcloud.php delete mode 100755 src/OAuth2/Client/Provider/Vkontakte.php delete mode 100755 src/OAuth2/Client/Provider/Windowslive.php delete mode 100755 src/OAuth2/Client/Provider/Yandex.php delete mode 100755 src/OAuth2/Client/Token.php delete mode 100755 src/OAuth2/Client/Token/Access.php delete mode 100755 src/OAuth2/Client/Token/Authorize.php diff --git a/src/OAuth2/Client/IDP.php b/src/OAuth2/Client/IDP.php deleted file mode 100644 index 092da0e6..00000000 --- a/src/OAuth2/Client/IDP.php +++ /dev/null @@ -1,230 +0,0 @@ -result = $result; - - $code = isset($result['code']) ? $result['code'] : 0; - - if (isset($result['error'])) { - - // OAuth 2.0 Draft 10 style - $message = $result['error']; - - } elseif (isset($result['message'])) { - - // cURL style - $message = $result['message']; - - } else { - - $message = 'Unknown Error.'; - - } - - parent::__construct($message['message'], $message['code']); - } - - public function getType() - { - if (isset($this->result['error'])) { - - $message = $this->result['error']; - - if (is_string($message)) { - // OAuth 2.0 Draft 10 style - return $message; - } - } - - return 'Exception'; - } - - /** - * To make debugging easier. - * - * @returns - * The string representation of the error. - */ - public function __toString() - { - $str = $this->getType() . ': '; - - if ($this->code != 0) { - $str .= $this->code . ': '; - } - - return $str . $this->message; - } - -} - -abstract class IDP { - - public $clientId = ''; - - public $clientSecret = ''; - - public $redirectUri = ''; - - public $name; - - public $uidKey = 'uid'; - - public $scopes = array(); - - public $method = 'post'; - - public $scopeSeperator = ','; - - public $responseType = 'json'; - - public function __construct($options) - { - foreach ($options as $option => $value) { - if (isset($this->{$option})) { - $this->{$option} = $value; - } - } - } - - abstract public function urlAuthorize(); - - abstract public function urlAccessToken(); - - abstract public function urlUserDetails(\OAuth2\Client\Token\Access $token); - - abstract public function userDetails($response, \OAuth2\Client\Token\Access $token); - - public function authorize($options = array()) - { - $state = md5(uniqid(rand(), TRUE)); - setcookie($this->name.'_authorize_state', $state); - - $params = array( - 'client_id' => $this->clientId, - 'redirect_uri' => $this->redirectUri, - 'state' => $state, - 'scope' => is_array($this->scope) ? implode($this->scopeSeperator, $this->scope) : $this->scope, - 'response_type' => isset($options['response_type']) ? $options['response_type'] : 'code', - 'approval_prompt' => 'force' // - google force-recheck - ); - - header('Location: ' . $this->urlAuthorize().'?'.http_build_query($params)); - exit; - } - - public function getAccessToken($code = NULL, $options = array()) - { - if ($code === NULL) { - throw new \BadMethodCallException('Missing authorization code'); - } - - $params = array( - 'client_id' => $this->clientId, - 'client_secret' => $this->clientSecret, - 'grant_type' => isset($options['grantType']) ? $options['grantType'] : 'authorization_code', - ); - - switch ($params['grant_type']) { - - case 'authorization_code': - $params['code'] = $code; - $params['redirect_uri'] = isset($options['redirectUri']) ? $options['redirectUri'] : $this->redirectUri; - break; - - case 'refresh_token': - $params['refresh_token'] = $code; - break; - - } - - try { - - switch ($this->method) { - - case 'get': - - $client = new GuzzleClient($this->urlAccessToken() . '?' . http_build_query($params)); - $request = $client->send(); - $response = $request->getBody(); - - break; - - case 'post': - - $client = new GuzzleClient($this->urlAccessToken()); - $request = $client->post(null, null, $params)->send(); - $response = $request->getBody(); - - break; - - } - - } - - catch (\Guzzle\Http\Exception\BadResponseException $e) - { - $raw_response = explode("\n", $e->getResponse()); - $response = end($raw_response); - } - - switch ($this->responseType) { - - case 'json': - $result = json_decode($response, true); - break; - - case 'string': - parse_str($response, $result); - break; - - } - - if (isset($result['error']) && ! empty($result['error'])) { - - throw new \OAuth2\Client\IDPException($result); - - } - - switch ($params['grant_type']) { - - case 'authorization_code': - return \OAuth2\Client\Token::factory('access', $result); - break; - - case 'refresh_token': - return \OAuth2\Client\Token::factory('refresh', $result); - break; - - } - } - - public function getUserDetails(\OAuth2\Client\Token\Access $token) - { - $url = $this->urlUserDetails($token); - - try { - $client = new GuzzleClient($url); - $request = $client->get()->send(); - $response = $request->getBody(); - - return $this->userDetails(json_decode($response), $token); - } - - catch (\Guzzle\Http\Exception\BadResponseException $e) - { - $raw_response = explode("\n", $e->getResponse()); - throw new \OAuth2\Client\IDPException(end($raw_response)); - } - } - -} \ No newline at end of file diff --git a/src/OAuth2/Client/Provider.php b/src/OAuth2/Client/Provider.php deleted file mode 100755 index 0762d57e..00000000 --- a/src/OAuth2/Client/Provider.php +++ /dev/null @@ -1,19 +0,0 @@ - $token->access_token, - )); - - $user = json_decode(file_get_contents($url)); - - return array( - 'uid' => $user->id, - 'nickname' => $user->username, - 'name' => $user->name, - 'first_name' => $user->first_name, - 'last_name' => $user->last_name, - 'email' => isset($user->email) ? $user->email : null, - 'location' => isset($user->hometown->name) ? $user->hometown->name : null, - 'description' => isset($user->bio) ? $user->bio : null, - 'image' => 'https://graph.facebook.com/me/picture?type=normal&access_token='.$token->access_token, - 'urls' => array( - 'Facebook' => $user->link, - ), - ); - } -} diff --git a/src/OAuth2/Client/Provider/Facebook.php b/src/OAuth2/Client/Provider/Facebook.php deleted file mode 100755 index cd41be17..00000000 --- a/src/OAuth2/Client/Provider/Facebook.php +++ /dev/null @@ -1,49 +0,0 @@ - $token->access_token, - )); - - $user = json_decode(file_get_contents($url)); - - return array( - 'uid' => $user->id, - 'nickname' => isset($user->username) ? $user->username : null, - 'name' => $user->name, - 'first_name' => $user->first_name, - 'last_name' => $user->last_name, - 'email' => isset($user->email) ? $user->email : null, - 'location' => isset($user->hometown->name) ? $user->hometown->name : null, - 'description' => isset($user->bio) ? $user->bio : null, - 'image' => 'https://graph.facebook.com/me/picture?type=normal&access_token='.$token->access_token, - 'urls' => array( - 'Facebook' => $user->link, - ), - ); - } -} diff --git a/src/OAuth2/Client/Provider/Foursquare.php b/src/OAuth2/Client/Provider/Foursquare.php deleted file mode 100755 index 1c2740f8..00000000 --- a/src/OAuth2/Client/Provider/Foursquare.php +++ /dev/null @@ -1,45 +0,0 @@ - $token->access_token, - )); - - $response = json_decode(file_get_contents($url)); - - $user = $response->response->user; - - // Create a response from the request - return array( - 'uid' => $user->id, - 'name' => sprintf('%s %s', $user->firstName, $user->lastName), - 'email' => $user->contact->email, - 'image' => $user->photo, - 'location' => $user->homeCity, - ); - } -} \ No newline at end of file diff --git a/src/OAuth2/Client/Provider/Github.php b/src/OAuth2/Client/Provider/Github.php deleted file mode 100755 index 5ca9b512..00000000 --- a/src/OAuth2/Client/Provider/Github.php +++ /dev/null @@ -1,43 +0,0 @@ - $token->access_token, - )); - - $user = json_decode(file_get_contents($url)); - - return array( - 'uid' => $user->id, - 'nickname' => $user->login, - 'name' => $user->name, - 'email' => $user->email, - 'urls' => array( - 'GitHub' => 'http://github.com/'.$user->login, - 'Blog' => $user->blog, - ), - ); - } -} \ No newline at end of file diff --git a/src/OAuth2/Client/Provider/Google.php b/src/OAuth2/Client/Provider/Google.php deleted file mode 100755 index b76d343b..00000000 --- a/src/OAuth2/Client/Provider/Google.php +++ /dev/null @@ -1,84 +0,0 @@ - 'Expected Authorization Code from '.ucfirst($this->name).' is missing')); - } - - return parent::access($code, $options); - } - - public function get_user_info(OAuth2_Token_Access $token) - { - $url = 'https://www.googleapis.com/oauth2/v1/userinfo?alt=json&'.http_build_query(array( - 'access_token' => $token->access_token, - )); - - $user = json_decode(file_get_contents($url), true); - return array( - 'uid' => $user['id'], - 'nickname' => url_title($user['name'], '_', true), - 'name' => $user['name'], - 'first_name' => $user['given_name'], - 'last_name' => $user['family_name'], - 'email' => $user['email'], - 'location' => null, - 'image' => (isset($user['picture'])) ? $user['picture'] : null, - 'description' => null, - 'urls' => array(), - ); - } -} diff --git a/src/OAuth2/Client/Provider/Instagram.php b/src/OAuth2/Client/Provider/Instagram.php deleted file mode 100755 index 39c8bef1..00000000 --- a/src/OAuth2/Client/Provider/Instagram.php +++ /dev/null @@ -1,48 +0,0 @@ -user; - - return array( - 'uid' => $user->id, - 'nickname' => $user->username, - 'name' => $user->full_name, - 'image' => $user->profile_picture, - 'urls' => array( - 'website' => $user->website, - ), - ); - } -} \ No newline at end of file diff --git a/src/OAuth2/Client/Provider/Mailchimp.php b/src/OAuth2/Client/Provider/Mailchimp.php deleted file mode 100755 index 818bd40d..00000000 --- a/src/OAuth2/Client/Provider/Mailchimp.php +++ /dev/null @@ -1,36 +0,0 @@ - $token->access_token, - ); - } -} diff --git a/src/OAuth2/Client/Provider/Mailru.php b/src/OAuth2/Client/Provider/Mailru.php deleted file mode 100755 index 25234a20..00000000 --- a/src/OAuth2/Client/Provider/Mailru.php +++ /dev/null @@ -1,73 +0,0 @@ - $value) { - $params .= "$key=$value"; - } - return md5($params . $secret_key); - } - - public function get_user_info(OAuth2_Token_Access $token) - { - $request_params = array( - 'app_id' => $this->client_id, - 'method' => 'users.getInfo', - 'uids' => $token->uid, - 'access_token' => $token->access_token, - 'secure' => 1 - ); - - $sig = $this->sign_server_server($request_params,$this->client_secret); - $url = 'http://www.appsmail.ru/platform/api?'.http_build_query($request_params).'&sig='.$sig; - - $user = json_decode(file_get_contents($url)); - - return array( - 'uid' => $user[0]->uid, - 'nickname' => $user[0]->nick, - 'name' => $user[0]->first_name.' '.$user[0]->last_name, - 'first_name' => $user[0]->first_name, - 'last_name' => $user[0]->last_name, - 'email' => isset($user[0]->email) ? $user[0]->email : null, - 'image' => isset($user[0]->pic_big) ? $user[0]->pic_big : null, - ); - } - - public function authorize($options = array()) - { - $state = md5(uniqid(rand(), TRUE)); - get_instance()->session->set_userdata('state', $state); - - $params = array( - 'client_id' => $this->client_id, - 'redirect_uri' => isset($options['redirect_uri']) ? $options['redirect_uri'] : $this->redirect_uri, - 'response_type' => 'code', - ); - - redirect($this->url_authorize().'?'.http_build_query($params)); - } -} diff --git a/src/OAuth2/Client/Provider/Paypal.php b/src/OAuth2/Client/Provider/Paypal.php deleted file mode 100755 index 72d065fe..00000000 --- a/src/OAuth2/Client/Provider/Paypal.php +++ /dev/null @@ -1,59 +0,0 @@ - $token->access_token - )); - - $user = json_decode(file_get_contents($url)); - $user = $user->identity; - - return array( - 'uid' => $user['userId'], - 'nickname' => url_title($user['fullName'], '_', true), - 'name' => $user['fullName'], - 'first_name' => $user['firstName'], - 'last_name' => $user['lastName'], - 'email' => $user['emails'][0], - 'location' => $user->addresses[0], - 'image' => null, - 'description' => null, - 'urls' => array( - 'PayPal' => null - ) - ); - } - -} diff --git a/src/OAuth2/Client/Provider/Soundcloud.php b/src/OAuth2/Client/Provider/Soundcloud.php deleted file mode 100755 index 83d9afbc..00000000 --- a/src/OAuth2/Client/Provider/Soundcloud.php +++ /dev/null @@ -1,51 +0,0 @@ - $token->access_token, - )); - - $user = json_decode(file_get_contents($url)); - - // Create a response from the request - return array( - 'uid' => $user->id, - 'nickname' => $user->username, - 'name' => $user->full_name, - 'location' => $user->country.' ,'.$user->country, - 'description' => $user->description, - 'image' => $user->avatar_url, - 'urls' => array( - 'MySpace' => $user->myspace_name, - 'Website' => $user->website, - ), - ); - } -} diff --git a/src/OAuth2/Client/Provider/Vkontakte.php b/src/OAuth2/Client/Provider/Vkontakte.php deleted file mode 100755 index bdad78e4..00000000 --- a/src/OAuth2/Client/Provider/Vkontakte.php +++ /dev/null @@ -1,54 +0,0 @@ - $token->uid, - 'fields' => implode(",",$scope), - 'access_token' => $token->access_token, - )); - - $user = json_decode(file_get_contents($url))->response; - - if(sizeof($user)==0) - return null; - else - $user = $user[0]; - - return array( - 'uid' => $user->uid, - 'nickname' => isset($user->nickname) ? $user->nickname : null, - 'name' => isset($user->name) ? $user->name : null, - 'first_name' => isset($user->first_name) ? $user->first_name : null, - 'last_name' => isset($user->last_name) ? $user->last_name : null, - 'email' => null, - 'location' => null, - 'description' => null, - 'image' => isset($user->photo_big) ? $user->photo_big : null, - 'urls' => array(), - ); - } -} diff --git a/src/OAuth2/Client/Provider/Windowslive.php b/src/OAuth2/Client/Provider/Windowslive.php deleted file mode 100755 index 8d489c3d..00000000 --- a/src/OAuth2/Client/Provider/Windowslive.php +++ /dev/null @@ -1,60 +0,0 @@ - $token->access_token, - )); - - // perform network request - $user = json_decode(file_get_contents($url)); - - // create a response from the request and return it - return array( - 'uid' => $user->id, - 'name' => $user->name, - 'nickname' => url_title($user->name, '_', true), -// 'location' => $user[''], # scope wl.postal_addresses is required - # but won't be implemented by default - 'locale' => $user->locale, - 'urls' => array('Windows Live' => $user->link), - ); - } -} diff --git a/src/OAuth2/Client/Provider/Yandex.php b/src/OAuth2/Client/Provider/Yandex.php deleted file mode 100755 index 7a8f4f80..00000000 --- a/src/OAuth2/Client/Provider/Yandex.php +++ /dev/null @@ -1,115 +0,0 @@ - array( - 'method' => 'GET', - 'header' => 'Authorization: OAuth '.$token->access_token - ) - ); - $_default_opts = stream_context_get_params(stream_context_get_default()); - - $opts = array_merge_recursive($_default_opts['options'], $opts); - $context = stream_context_create($opts); - $url = 'http://api-yaru.yandex.ru/me/?format=json'; - - $user = json_decode(file_get_contents($url,false,$context)); - - preg_match("/\d+$/",$user->id,$uid); - - return array( - 'uid' => $uid[0], - 'nickname' => isset($user->name) ? $user->name : null, - 'name' => isset($user->name) ? $user->name : null, - 'first_name' => isset($user->first_name) ? $user->first_name : null, - 'last_name' => isset($user->last_name) ? $user->last_name : null, - 'email' => isset($user->email) ? $user->email : null, - 'location' => isset($user->hometown->name) ? $user->hometown->name : null, - 'description' => isset($user->bio) ? $user->bio : null, - 'image' => $user->links->userpic, - ); - } - - public function access($code, $options = array()) - { - $params = array( - 'client_id' => $this->client_id, - 'client_secret' => $this->client_secret, - 'grant_type' => isset($options['grant_type']) ? $options['grant_type'] : 'authorization_code', - ); - - switch ($params['grant_type']) - { - case 'authorization_code': - $params['code'] = $code; - $params['redirect_uri'] = isset($options['redirect_uri']) ? $options['redirect_uri'] : $this->redirect_uri; - break; - - case 'refresh_token': - $params['refresh_token'] = $code; - break; - } - - $response = null; - $url = $this->url_access_token(); - - $curl = curl_init($url); - - $headers[] = 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8;'; - curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); - -// curl_setopt($curl, CURLOPT_USERAGENT, 'yamolib-php'); - curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); - curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30); - curl_setopt($curl, CURLOPT_TIMEOUT, 80); - curl_setopt($curl, CURLOPT_POST, true); - curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($params)); - curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); - // curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true); - // curl_setopt($curl, CURLOPT_CAINFO, dirname(__FILE__) . '/../data/ca-certificate.crt'); - - $response = curl_exec($curl); - curl_close($curl); - - $return = json_decode($response, true); - - if ( ! empty($return['error'])) - { - throw new OAuth2_Exception($return); - } - - switch ($params['grant_type']) - { - case 'authorization_code': - return OAuth2_Token::factory('access', $return); - break; - - case 'refresh_token': - return OAuth2_Token::factory('refresh', $return); - break; - } - } - -} diff --git a/src/OAuth2/Client/Token.php b/src/OAuth2/Client/Token.php deleted file mode 100755 index e4bae4bc..00000000 --- a/src/OAuth2/Client/Token.php +++ /dev/null @@ -1,46 +0,0 @@ -$key; - } - - /** - * Return a boolean if the property is set - * - * @param string variable name - * @return bool - */ - public function __isset($key) - { - return isset($this->$key); - } - -} // End Token diff --git a/src/OAuth2/Client/Token/Access.php b/src/OAuth2/Client/Token/Access.php deleted file mode 100755 index dd508c41..00000000 --- a/src/OAuth2/Client/Token/Access.php +++ /dev/null @@ -1,79 +0,0 @@ -accessToken = $options['access_token']; - - // Some providers (not many) give the uid here, so lets take it - isset($options['uid']) and $this->uid = $options['uid']; - - //Vkontakte uses user_id instead of uid - isset($options['user_id']) and $this->uid = $options['user_id']; - - //Mailru uses x_mailru_vid instead of uid - isset($options['x_mailru_vid']) and $this->uid = $options['x_mailru_vid']; - - // We need to know when the token expires, add num. seconds to current time - isset($options['expires_in']) and $this->expires = time() + ((int) $options['expires_in']); - - // Facebook is just being a spec ignoring jerk - isset($options['expires']) and $this->expires = time() + ((int) $options['expires']); - - // Grab a refresh token so we can update access tokens when they expires - isset($options['refresh_token']) and $this->refreshToken = $options['refresh_token']; - } - - /** - * Returns the token key. - * - * @return string - */ - public function __toString() - { - return (string) $this->accessToken; - } - -} \ No newline at end of file diff --git a/src/OAuth2/Client/Token/Authorize.php b/src/OAuth2/Client/Token/Authorize.php deleted file mode 100755 index 2e9695cf..00000000 --- a/src/OAuth2/Client/Token/Authorize.php +++ /dev/null @@ -1,55 +0,0 @@ -code = $options['code']; - $this->redirectUri = $options['redirect_uri']; - } - - /** - * Returns the token key. - * - * @return string - */ - public function __toString() - { - return (string) $this->code; - } - -} \ No newline at end of file