From a0278efb4ee140b8720ecf89a8e25fbe978d8852 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Thu, 29 Mar 2012 13:33:49 +0100 Subject: [PATCH 01/31] Added Blooie driver. --- libraries/Provider/Blooie.php | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 libraries/Provider/Blooie.php diff --git a/libraries/Provider/Blooie.php b/libraries/Provider/Blooie.php new file mode 100644 index 0000000..1c6c545 --- /dev/null +++ b/libraries/Provider/Blooie.php @@ -0,0 +1,43 @@ + $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->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, + ), + ); + } +} From 127e90ffe3d20fd94db460207b01a8d2e6319068 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Wed, 4 Apr 2012 10:46:23 +0100 Subject: [PATCH 02/31] Environment updates for blooie provider. --- libraries/Provider/Blooie.php | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/libraries/Provider/Blooie.php b/libraries/Provider/Blooie.php index 1c6c545..d30e43d 100644 --- a/libraries/Provider/Blooie.php +++ b/libraries/Provider/Blooie.php @@ -8,13 +8,38 @@ class OAuth2_Provider_Blooie extends OAuth2_Provider public function url_authorize() { - return 'http://local.bloo.ie/oauth'; + switch (ENVIRONMENT) + { + case PYRO_DEVELOPMENT: + return 'http://local.bloo.ie/oauth'; + + case PYRO_STAGING: + return 'http://blooie-staging.pagodabox.com/oauth'; + + case PYRO_PRODUCTIION: + return 'https://bloo.ie/oauth'; + + default: + exit('What the crap?!'); + } + } public function url_access_token() { - return 'http://local.bloo.ie/oauth/access_token'; - } + switch (ENVIRONMENT) + { + case PYRO_DEVELOPMENT: + return 'http://local.bloo.ie/oauth/access_token'; + + case PYRO_STAGING: + return 'http://blooie-staging.pagodabox.com/oauth/access_token'; + + case PYRO_PRODUCTIION: + return 'https://bloo.ie/oauth/access_token'; + + default: + } public function get_user_info(OAuth2_Token_Access $token) { From efe14d2fb8844b28135b3bb8bb6dbbd7d998b6c1 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sun, 8 Apr 2012 17:02:02 +0200 Subject: [PATCH 03/31] Lowercase files don't exist so ucfirst the provider name --- libraries/OAuth2.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/OAuth2.php b/libraries/OAuth2.php index 47d9ccc..268f79e 100644 --- a/libraries/OAuth2.php +++ b/libraries/OAuth2.php @@ -23,7 +23,7 @@ class OAuth2 { */ public static function provider($name, array $options = NULL) { - include_once 'Provider/'.strtolower($name).'.php'; + include_once 'Provider/'.ucfirst($name).'.php'; $class = 'OAuth2_Provider_'.ucfirst($name); From c4c22f5576a1926bb113d6035fa6e5381702d357 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sun, 8 Apr 2012 17:09:25 +0200 Subject: [PATCH 04/31] Token/access.php and Token/authorise.php don't exist (but Access.php and Authorise.php do) --- libraries/Token.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/Token.php b/libraries/Token.php index 5828448..f45e316 100644 --- a/libraries/Token.php +++ b/libraries/Token.php @@ -21,7 +21,7 @@ abstract class OAuth2_Token { */ public static function factory($name = 'access', array $options = null) { - include_once 'Token/'.strtolower($name).'.php'; + include_once 'Token/'.ucfirst($name).'.php'; $class = 'OAuth2_Token_'.ucfirst($name); From 114a1ca7fa5a9533a5227b73082c34d14bff44c9 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sun, 8 Apr 2012 17:19:38 +0200 Subject: [PATCH 05/31] Added missing getType() function --- libraries/Exception.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/libraries/Exception.php b/libraries/Exception.php index 377a7e3..dfdee0d 100644 --- a/libraries/Exception.php +++ b/libraries/Exception.php @@ -42,6 +42,27 @@ public function __construct($result) parent::__construct($message, $code); } + + /** + * Returns the associated type for the error. This will default to + * 'Exception' when a type is not available. + * + * @return + * The type for the error. + */ + 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. From 79a204280fbe4a97258041430859a10915072ccf Mon Sep 17 00:00:00 2001 From: Compilerrr Date: Wed, 18 Apr 2012 00:06:02 +0400 Subject: [PATCH 06/31] Update libraries/Token/Access.php --- libraries/Token/Access.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libraries/Token/Access.php b/libraries/Token/Access.php index 78548d6..5b9953e 100644 --- a/libraries/Token/Access.php +++ b/libraries/Token/Access.php @@ -53,6 +53,9 @@ public function __construct(array $options = null) // 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']; + // 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']); From 8c2383808a23c4ee61b4fe27f4734a37a1213bab Mon Sep 17 00:00:00 2001 From: Lavr Lyndin Date: Wed, 18 Apr 2012 00:49:15 +0400 Subject: [PATCH 07/31] russian providers --- libraries/Provider/Vkontakte.php | 58 +++++++++++++++ libraries/Provider/Yandex.php | 123 +++++++++++++++++++++++++++++++ 2 files changed, 181 insertions(+) create mode 100644 libraries/Provider/Vkontakte.php create mode 100644 libraries/Provider/Yandex.php diff --git a/libraries/Provider/Vkontakte.php b/libraries/Provider/Vkontakte.php new file mode 100644 index 0000000..f46fe32 --- /dev/null +++ b/libraries/Provider/Vkontakte.php @@ -0,0 +1,58 @@ + 'your_client_id', + 'secret' => 'your_client_secret', + )); + } + + public function url_authorize() + { + return 'http://oauth.vk.com/authorize'; + } + + public function url_access_token() + { + return 'https://oauth.vk.com/access_token'; + } + + public function get_user_info(OAuth2_Token_Access $token) + { + $scope = array('nickname', 'screen_name','photo_big'); + $url = 'https://api.vk.com/method/users.get?'.http_build_query(array( + 'uids' => $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->id, + '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/libraries/Provider/Yandex.php b/libraries/Provider/Yandex.php new file mode 100644 index 0000000..8814ce1 --- /dev/null +++ b/libraries/Provider/Yandex.php @@ -0,0 +1,123 @@ + 'your_client_id', + 'secret' => 'your_secret_id', + )); + } + + public function url_authorize() + { + return 'https://oauth.yandex.ru/authorize'; + } + + public function url_access_token() + { + return 'https://oauth.yandex.ru/token'; + } + + public function get_user_info(OAuth2_Token_Access $token) + { + $opts = array( + 'http' => 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; + } + } + +} From 68f0affc45ad3ee49fc99ce0dd0757eecd76efa0 Mon Sep 17 00:00:00 2001 From: Lavr Lyndin Date: Thu, 19 Apr 2012 20:30:55 +0400 Subject: [PATCH 08/31] constructor with default configuration removed --- libraries/Provider/Vkontakte.php | 8 -------- libraries/Provider/Yandex.php | 8 -------- 2 files changed, 16 deletions(-) diff --git a/libraries/Provider/Vkontakte.php b/libraries/Provider/Vkontakte.php index f46fe32..85a6641 100644 --- a/libraries/Provider/Vkontakte.php +++ b/libraries/Provider/Vkontakte.php @@ -9,14 +9,6 @@ class OAuth2_Provider_Vkontakte extends OAuth2_Provider { - public function __construct(array $options = array()) - { - parent::__construct(array( - 'id' => 'your_client_id', - 'secret' => 'your_client_secret', - )); - } - public function url_authorize() { return 'http://oauth.vk.com/authorize'; diff --git a/libraries/Provider/Yandex.php b/libraries/Provider/Yandex.php index 8814ce1..7a8f4f8 100644 --- a/libraries/Provider/Yandex.php +++ b/libraries/Provider/Yandex.php @@ -11,14 +11,6 @@ class OAuth2_Provider_Yandex extends OAuth2_Provider { public $method = 'POST'; - public function __construct(array $options = array()) - { - parent::__construct(array( - 'id' => 'your_client_id', - 'secret' => 'your_secret_id', - )); - } - public function url_authorize() { return 'https://oauth.yandex.ru/authorize'; From 76cc29789ea8cb13580f175acb9027f685b898e8 Mon Sep 17 00:00:00 2001 From: Calvin Froedge Date: Sat, 21 Apr 2012 02:57:42 -0500 Subject: [PATCH 09/31] Removed direct script access allowed thingy to work outside CodeIgniter --- libraries/Provider/Facebook.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/Provider/Facebook.php b/libraries/Provider/Facebook.php index 7d0433e..5cb6639 100644 --- a/libraries/Provider/Facebook.php +++ b/libraries/Provider/Facebook.php @@ -1,4 +1,4 @@ - Date: Sat, 28 Apr 2012 17:44:08 -0300 Subject: [PATCH 10/31] Update config/autoload.php --- config/autoload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/autoload.php b/config/autoload.php index caa6440..2565b85 100644 --- a/config/autoload.php +++ b/config/autoload.php @@ -1,3 +1,3 @@ Date: Wed, 2 May 2012 19:05:35 +0200 Subject: [PATCH 11/31] Fix for the nickname PHP notice if the Facebook user doesn't have a username set. --- libraries/Provider/Facebook.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/Provider/Facebook.php b/libraries/Provider/Facebook.php index 5cb6639..91f27a0 100644 --- a/libraries/Provider/Facebook.php +++ b/libraries/Provider/Facebook.php @@ -34,7 +34,7 @@ public function get_user_info(OAuth2_Token_Access $token) // Create a response from the request return array( 'uid' => $user->id, - 'nickname' => $user->username, + 'nickname' => isset($user->username) ? $user->username : null, 'name' => $user->name, 'first_name' => $user->first_name, 'last_name' => $user->last_name, From e4a9decda31491fb1406320b7ee2801866bdc922 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 9 May 2012 23:00:29 +0400 Subject: [PATCH 12/31] mail.ru provider added --- libraries/Provider/Mailru.php | 90 +++++++++++++++++++++++++++++++++++ libraries/Token/Access.php | 3 ++ 2 files changed, 93 insertions(+) create mode 100644 libraries/Provider/Mailru.php diff --git a/libraries/Provider/Mailru.php b/libraries/Provider/Mailru.php new file mode 100644 index 0000000..48e7835 --- /dev/null +++ b/libraries/Provider/Mailru.php @@ -0,0 +1,90 @@ + '675238', + 'secret' => 'e7ed5c1dd9fb7a80b45da73917320491', + )); + } + + public function url_authorize() + { + return 'https://connect.mail.ru/oauth/authorize'; + } + + public function url_access_token() + { + return 'https://connect.mail.ru/oauth/token'; + } + + function sign_server_server(array $request_params, $secret_key) { + ksort($request_params); + $params = ''; + foreach ($request_params as $key => $value) { + $params .= "$key=$value"; + } + return md5($params . $secret_key); + } + + public function get_user_info(OAuth2_Token_Access $token) + { +// echo $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; +// echo $url; + + $user = json_decode(file_get_contents($url)); + + // Create a response from the request + 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/libraries/Token/Access.php b/libraries/Token/Access.php index 5b9953e..51829b1 100644 --- a/libraries/Token/Access.php +++ b/libraries/Token/Access.php @@ -56,6 +56,9 @@ public function __construct(array $options = null) //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']); From 40f6a4c4456aa768f0b9dc56fb73312237069d2c Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 9 May 2012 23:03:02 +0400 Subject: [PATCH 13/31] conf removed --- libraries/Provider/Mailru.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/libraries/Provider/Mailru.php b/libraries/Provider/Mailru.php index 48e7835..317bc62 100644 --- a/libraries/Provider/Mailru.php +++ b/libraries/Provider/Mailru.php @@ -16,16 +16,6 @@ class OAuth2_Provider_Mailru extends OAuth2_Provider public function __construct(array $options = array()) { -//ID:675238 -//Приватный ключ:85c113000674f46477445994a5e570b9 -//Секретный ключ:e7ed5c1dd9fb7a80b45da73917320491 - - parent::__construct(array( - 'id' => '675238', - 'secret' => 'e7ed5c1dd9fb7a80b45da73917320491', - )); - } - public function url_authorize() { return 'https://connect.mail.ru/oauth/authorize'; From 472f0f66fa94af361a0cc6e80f2777d5192b0e4b Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 14 May 2012 08:23:08 +0400 Subject: [PATCH 14/31] comments removed --- libraries/Provider/Mailru.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/libraries/Provider/Mailru.php b/libraries/Provider/Mailru.php index 317bc62..aebea81 100644 --- a/libraries/Provider/Mailru.php +++ b/libraries/Provider/Mailru.php @@ -9,8 +9,6 @@ class OAuth2_Provider_Mailru extends OAuth2_Provider { - protected $scope = array('offline_access', 'email', 'read_stream'); - public $method = 'POST'; public function __construct(array $options = array()) @@ -37,7 +35,6 @@ function sign_server_server(array $request_params, $secret_key) { public function get_user_info(OAuth2_Token_Access $token) { -// echo $token; $request_params = array( 'app_id' => $this->client_id, 'method' => 'users.getInfo', @@ -48,11 +45,9 @@ public function get_user_info(OAuth2_Token_Access $token) $sig = $this->sign_server_server($request_params,$this->client_secret); $url = 'http://www.appsmail.ru/platform/api?'.http_build_query($request_params).'&sig='.$sig; -// echo $url; $user = json_decode(file_get_contents($url)); - // Create a response from the request return array( 'uid' => $user[0]->uid, 'nickname' => $user[0]->nick, From 44c3daa308476e0ed5da5ece66897a05aec729e1 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 14 May 2012 22:24:41 +0400 Subject: [PATCH 15/31] method made protected --- libraries/Provider/Mailru.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/Provider/Mailru.php b/libraries/Provider/Mailru.php index aebea81..fc83b95 100644 --- a/libraries/Provider/Mailru.php +++ b/libraries/Provider/Mailru.php @@ -24,7 +24,8 @@ public function url_access_token() return 'https://connect.mail.ru/oauth/token'; } - function sign_server_server(array $request_params, $secret_key) { + protected function sign_server_server(array $request_params, $secret_key) + { ksort($request_params); $params = ''; foreach ($request_params as $key => $value) { From 84501b8df007a8a15ed747e6c80424768da70fd9 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 14 May 2012 22:49:10 +0400 Subject: [PATCH 16/31] constructor removed --- libraries/Provider/Mailru.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/libraries/Provider/Mailru.php b/libraries/Provider/Mailru.php index fc83b95..25234a2 100644 --- a/libraries/Provider/Mailru.php +++ b/libraries/Provider/Mailru.php @@ -11,9 +11,6 @@ class OAuth2_Provider_Mailru extends OAuth2_Provider { public $method = 'POST'; - public function __construct(array $options = array()) - { - public function url_authorize() { return 'https://connect.mail.ru/oauth/authorize'; From f357daf266c4bfc09a09186c396c75a67a5f6cf0 Mon Sep 17 00:00:00 2001 From: Michiel Vugteveen Date: Tue, 29 May 2012 12:03:24 +0200 Subject: [PATCH 17/31] instagram fix --- libraries/Provider/Instagram.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/Provider/Instagram.php b/libraries/Provider/Instagram.php index 4df8f6c..39c8bef 100644 --- a/libraries/Provider/Instagram.php +++ b/libraries/Provider/Instagram.php @@ -9,7 +9,7 @@ * @license http://philsturgeon.co.uk/code/dbad-license */ -class OAuth_Provider_Instagram extends OAuth2_Provider +class OAuth2_Provider_Instagram extends OAuth2_Provider { /** * @var string scope separator, most use "," but some like Google are spaces From df14d624fc60e931f9adc8dddb48107bf4790172 Mon Sep 17 00:00:00 2001 From: Michiel Vugteveen Date: Tue, 29 May 2012 12:03:54 +0200 Subject: [PATCH 18/31] class name ucfirst fixes --- libraries/OAuth2.php | 14 ++++++++------ libraries/Token.php | 12 +++++++----- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/libraries/OAuth2.php b/libraries/OAuth2.php index 268f79e..15f6948 100644 --- a/libraries/OAuth2.php +++ b/libraries/OAuth2.php @@ -1,5 +1,5 @@ */ class OAuth2 { - + /** * Create a new provider. * @@ -23,11 +23,13 @@ class OAuth2 { */ public static function provider($name, array $options = NULL) { - include_once 'Provider/'.ucfirst($name).'.php'; - - $class = 'OAuth2_Provider_'.ucfirst($name); + $name = ucfirst(strtolower($name)); + + include_once 'Provider/'.$name.'.php'; + + $class = 'OAuth2_Provider_'.$name; return new $class($options); } - + } \ No newline at end of file diff --git a/libraries/Token.php b/libraries/Token.php index f45e316..4521673 100644 --- a/libraries/Token.php +++ b/libraries/Token.php @@ -21,10 +21,12 @@ abstract class OAuth2_Token { */ public static function factory($name = 'access', array $options = null) { - include_once 'Token/'.ucfirst($name).'.php'; - - $class = 'OAuth2_Token_'.ucfirst($name); - + $name = ucfirst(strtolower($name)); + + include_once 'Token/'.$name.'.php'; + + $class = 'OAuth2_Token_'.$name; + return new $class($options); } @@ -41,7 +43,7 @@ public function __get($key) { return $this->$key; } - + /** * Return a boolean if the property is set * From f6d2673ac8bda6733111190ad600b0900f731728 Mon Sep 17 00:00:00 2001 From: Calvin Froedge Date: Tue, 29 May 2012 15:04:19 -0500 Subject: [PATCH 19/31] Picture was not returned in the oauth authentication I did in my app --- libraries/Provider/Google.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/Provider/Google.php b/libraries/Provider/Google.php index 0bf0df3..b76d343 100755 --- a/libraries/Provider/Google.php +++ b/libraries/Provider/Google.php @@ -76,7 +76,7 @@ public function get_user_info(OAuth2_Token_Access $token) 'last_name' => $user['family_name'], 'email' => $user['email'], 'location' => null, - 'image' => $user['picture'], + 'image' => (isset($user['picture'])) ? $user['picture'] : null, 'description' => null, 'urls' => array(), ); From 389f08b4b002e0d34138e84d64139b9f24ee4848 Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 11 Jul 2012 18:32:49 +0300 Subject: [PATCH 20/31] Vkontakte returns json so method should be POST, not GET --- libraries/Provider/Vkontakte.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libraries/Provider/Vkontakte.php b/libraries/Provider/Vkontakte.php index 85a6641..bdad78e 100644 --- a/libraries/Provider/Vkontakte.php +++ b/libraries/Provider/Vkontakte.php @@ -9,6 +9,9 @@ class OAuth2_Provider_Vkontakte extends OAuth2_Provider { + protected $method = 'POST'; + public $uid_key = 'user_id'; + public function url_authorize() { return 'http://oauth.vk.com/authorize'; @@ -29,13 +32,14 @@ public function get_user_info(OAuth2_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->id, + '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, From 56934803ceaef0d244e2e6512dc62c243106c085 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Wed, 18 Jul 2012 09:45:35 +0100 Subject: [PATCH 21/31] Updated version numbers. --- README.md | 2 +- spark.info | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7a9f4ce..2e04c08 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ class Auth extends CI_Controller { $this->load->helper('url_helper'); - $this->load->spark('oauth2/0.3.0'); + $this->load->spark('oauth2/0.3.1'); $provider = $this->oauth2->provider($provider, array( 'id' => 'your-client-id', diff --git a/spark.info b/spark.info index 85c013c..1506939 100644 --- a/spark.info +++ b/spark.info @@ -1,3 +1,3 @@ name: codeigniter-oauth2 -version: 0.3.0 -compatibility: 2.0.0 \ No newline at end of file +version: 0.3.1 +compatibility: 2.1.0 \ No newline at end of file From 69f106e7105ffefd52cdd869d2d97fefed5eb51b Mon Sep 17 00:00:00 2001 From: Brennan Novak Date: Mon, 13 Aug 2012 16:28:48 -0700 Subject: [PATCH 22/31] added provider for App.net --- libraries/Provider/Appnet.php | 55 +++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 libraries/Provider/Appnet.php diff --git a/libraries/Provider/Appnet.php b/libraries/Provider/Appnet.php new file mode 100644 index 0000000..14203a1 --- /dev/null +++ b/libraries/Provider/Appnet.php @@ -0,0 +1,55 @@ + $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->name + ); + + } + +} \ No newline at end of file From 58462048f93f8fd040fdb9a4d148d4522d4415e4 Mon Sep 17 00:00:00 2001 From: Rasmus Schultz Date: Wed, 24 Oct 2012 08:46:02 -0400 Subject: [PATCH 23/31] add missing closing brace --- libraries/Provider/Blooie.php | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/Provider/Blooie.php b/libraries/Provider/Blooie.php index d30e43d..212d788 100644 --- a/libraries/Provider/Blooie.php +++ b/libraries/Provider/Blooie.php @@ -40,6 +40,7 @@ public function url_access_token() default: } + } public function get_user_info(OAuth2_Token_Access $token) { From 84c6f2318d534e09af17de6c16922a92a47f48a2 Mon Sep 17 00:00:00 2001 From: Rasmus Schultz Date: Wed, 24 Oct 2012 08:46:42 -0400 Subject: [PATCH 24/31] add missing abstract get_user_info() method --- libraries/Provider.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/libraries/Provider.php b/libraries/Provider.php index 190c921..767f425 100644 --- a/libraries/Provider.php +++ b/libraries/Provider.php @@ -51,8 +51,8 @@ abstract class OAuth2_Provider * * Any of the provider options can be set here, such as app_id or secret. * - * @param array provider options - * @return void + * @param array $options provider options + * @throws Exception if a required option is not provided */ public function __construct(array $options = array()) { @@ -82,7 +82,7 @@ public function __construct(array $options = array()) * // Get the provider signature * $signature = $provider->signature; * - * @param string variable name + * @param string $key variable name * @return mixed */ public function __get($key) @@ -108,12 +108,18 @@ abstract public function url_authorize(); */ abstract public function url_access_token(); + /** + * @param OAuth2_Token_Access $token + * @return array basic user info + */ + abstract public function get_user_info(OAuth2_Token_Access $token); + /* * Get an authorization code from Facebook. Redirects to Facebook, which this redirects back to the app using the redirect address you've set. */ public function authorize($options = array()) { - $state = md5(uniqid(rand(), TRUE)); + $state = md5(uniqid(rand(), true)); get_instance()->session->set_userdata('state', $state); $params = array( @@ -154,7 +160,7 @@ public function access($code, $options = array()) break; } - $response = null; + $response = null; $url = $this->url_access_token(); switch ($this->method) From 2faa3f95455c346b7e8e4c4e8f372df6271e0715 Mon Sep 17 00:00:00 2001 From: Rasmus Schultz Date: Wed, 24 Oct 2012 08:46:56 -0400 Subject: [PATCH 25/31] fix bad/missing annotations --- libraries/Exception.php | 6 ++---- libraries/OAuth2.php | 6 +++--- libraries/Token.php | 10 +++++----- libraries/Token/Access.php | 5 +++-- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/libraries/Exception.php b/libraries/Exception.php index dfdee0d..20bda9d 100644 --- a/libraries/Exception.php +++ b/libraries/Exception.php @@ -47,8 +47,7 @@ public function __construct($result) * Returns the associated type for the error. This will default to * 'Exception' when a type is not available. * - * @return - * The type for the error. + * @return string The type for the error. */ public function getType() { @@ -67,8 +66,7 @@ public function getType() /** * To make debugging easier. * - * @returns - * The string representation of the error. + * @return string The string representation of the error. */ public function __toString() { diff --git a/libraries/OAuth2.php b/libraries/OAuth2.php index 15f6948..cb594cb 100644 --- a/libraries/OAuth2.php +++ b/libraries/OAuth2.php @@ -17,9 +17,9 @@ class OAuth2 { * // Load the Twitter provider * $provider = $this->oauth2->provider('twitter'); * - * @param string provider name - * @param array provider options - * @return OAuth_Provider + * @param string $name provider name + * @param array $options provider options + * @return OAuth2_Provider */ public static function provider($name, array $options = NULL) { diff --git a/libraries/Token.php b/libraries/Token.php index 4521673..512b006 100644 --- a/libraries/Token.php +++ b/libraries/Token.php @@ -15,9 +15,9 @@ abstract class OAuth2_Token { * * $token = OAuth2_Token::factory($name); * - * @param string token type - * @param array token options - * @return Token + * @param string $name token type + * @param array $options token options + * @return OAuth2_Token */ public static function factory($name = 'access', array $options = null) { @@ -36,7 +36,7 @@ public static function factory($name = 'access', array $options = null) * // Get the token secret * $secret = $token->secret; * - * @param string variable name + * @param string $key variable name * @return mixed */ public function __get($key) @@ -50,7 +50,7 @@ public function __get($key) * // Get the token secret * if ($token->secret) exit('YAY SECRET'); * - * @param string variable name + * @param string $key variable name * @return bool */ public function __isset($key) diff --git a/libraries/Token/Access.php b/libraries/Token/Access.php index 51829b1..e1714b2 100644 --- a/libraries/Token/Access.php +++ b/libraries/Token/Access.php @@ -33,8 +33,9 @@ class OAuth2_Token_Access extends OAuth2_Token /** * Sets the token, expiry, etc values. * - * @param array token options - * @return void + * @param array $options token options + * + * @throws Exception if required options are missing */ public function __construct(array $options = null) { From 8ca474619bb27d1e7a6bc8dc2e9053a8b9b9d8f7 Mon Sep 17 00:00:00 2001 From: Phil Martinez Date: Sat, 1 Dec 2012 16:18:17 -0600 Subject: [PATCH 26/31] Append $params with provider specific attr. --- libraries/Provider.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libraries/Provider.php b/libraries/Provider.php index 190c921..4029407 100644 --- a/libraries/Provider.php +++ b/libraries/Provider.php @@ -125,6 +125,8 @@ public function authorize($options = array()) 'approval_prompt' => 'force' // - google force-recheck ); + $params = array_merge($params, $this->params); + redirect($this->url_authorize().'?'.http_build_query($params)); } @@ -141,6 +143,8 @@ public function access($code, $options = array()) 'client_secret' => $this->client_secret, 'grant_type' => isset($options['grant_type']) ? $options['grant_type'] : 'authorization_code', ); + + $params = array_merge($params, $this->params); switch ($params['grant_type']) { From 05d9b0c1a61b8150c7caecbac53ede165de7727a Mon Sep 17 00:00:00 2001 From: Vytenis Date: Fri, 28 Dec 2012 12:31:18 +0200 Subject: [PATCH 27/31] Update libraries/Provider/Paypal.php fixed #39 --- libraries/Provider/Paypal.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/Provider/Paypal.php b/libraries/Provider/Paypal.php index 72d065f..12920e4 100644 --- a/libraries/Provider/Paypal.php +++ b/libraries/Provider/Paypal.php @@ -37,8 +37,8 @@ public function get_user_info(OAuth2_Token_Access $token) 'oauth_token' => $token->access_token )); - $user = json_decode(file_get_contents($url)); - $user = $user->identity; + $user = json_decode(file_get_contents($url),true); + $user = $user['identity']; return array( 'uid' => $user['userId'], From 784e9f12760e2f95706b8aa60012c9d399d70786 Mon Sep 17 00:00:00 2001 From: Vytenis Date: Mon, 18 Feb 2013 22:28:52 +0200 Subject: [PATCH 28/31] Update libraries/Provider/Paypal.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixed #45 --- libraries/Provider/Paypal.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/Provider/Paypal.php b/libraries/Provider/Paypal.php index 12920e4..499b7c9 100644 --- a/libraries/Provider/Paypal.php +++ b/libraries/Provider/Paypal.php @@ -14,7 +14,7 @@ class OAuth2_Provider_Paypal extends OAuth2_Provider /** * @var string default scope (useful if a scope is required for user info) */ - protected $scope = array('https://identity.x.com/xidentity/resources/profile/me'); + protected $scope = array('https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/userinfo'); /** * @var string the method to use when requesting tokens @@ -23,17 +23,17 @@ class OAuth2_Provider_Paypal extends OAuth2_Provider public function url_authorize() { - return 'https://identity.x.com/xidentity/resources/authorize'; + return 'https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize'; } public function url_access_token() { - return 'https://identity.x.com/xidentity/oauthtokenservice'; + return 'https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/tokenservice'; } public function get_user_info(OAuth2_Token_Access $token) { - $url = 'https://identity.x.com/xidentity/resources/profile/me?' . http_build_query(array( + $url = 'https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/userinfo?' . http_build_query(array( 'oauth_token' => $token->access_token )); From 9482a86fee33d293dc8977491b679aca97ed8134 Mon Sep 17 00:00:00 2001 From: Benjamin Hill Date: Thu, 28 Feb 2013 10:32:25 -0800 Subject: [PATCH 29/31] New provider for just released LinkedIn oAuth2 --- libraries/Provider/Linkedin.php | 66 +++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 libraries/Provider/Linkedin.php diff --git a/libraries/Provider/Linkedin.php b/libraries/Provider/Linkedin.php new file mode 100644 index 0000000..979500c --- /dev/null +++ b/libraries/Provider/Linkedin.php @@ -0,0 +1,66 @@ + $token->access_token, + )); + $user = json_decode(file_get_contents($url_profile), true); + + $url_email = 'https://api.linkedin.com/v1/people/~/email-address?format=json&' . http_build_query(array( + 'oauth2_access_token' => $token->access_token, + )); + $user_email = json_decode(file_get_contents($url_email), true); + + return array( + 'first_name' => $user['firstName'], + 'last_name' => $user['lastName'], + 'title' => $user['headline'], + 'email' => $user_email, + 'urls' => array( + 'LinkedIn' => $user->siteStandardProfileRequest->url + ), + ); + } + +} From 0c3dc203f17a8e2603ef8a539f3f5eda0a8fc4a2 Mon Sep 17 00:00:00 2001 From: Benjamin Hill Date: Thu, 28 Feb 2013 11:08:06 -0800 Subject: [PATCH 30/31] User ID, description, name --- libraries/Provider/Linkedin.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/libraries/Provider/Linkedin.php b/libraries/Provider/Linkedin.php index 979500c..3878b47 100644 --- a/libraries/Provider/Linkedin.php +++ b/libraries/Provider/Linkedin.php @@ -9,8 +9,8 @@ * * @package CodeIgniter/OAuth2 * @category Provider - * @author Benjamin Hill benjaminhill@gmail.com - * @copyright (c) Same as parent project + * @author Benjamin Hill + * @copyright (c) None * @license http://philsturgeon.co.uk/code/dbad-license */ class OAuth2_Provider_Linkedin extends OAuth2_Provider { @@ -52,15 +52,19 @@ public function get_user_info(OAuth2_Token_Access $token) { )); $user_email = json_decode(file_get_contents($url_email), true); + $args = array(); + parse_str(parse_url(http://github.com/$user['siteStandardProfileRequest']['url'],%20PHP_URL_QUERY), $args); + $user_id = $args['id']; return array( + 'id' => $user_id, 'first_name' => $user['firstName'], 'last_name' => $user['lastName'], - 'title' => $user['headline'], + 'name' => $user['firstName'] . ' ' . $user['lastName'], + 'description' => $user['headline'], 'email' => $user_email, 'urls' => array( - 'LinkedIn' => $user->siteStandardProfileRequest->url + 'LinkedIn' => $user['siteStandardProfileRequest']['url'] ), ); } - } From d2d3b0e73074d7c8b8e7a0ab02f75dfcf1937ed8 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Fri, 21 Feb 2014 10:53:00 -0500 Subject: [PATCH 31/31] Update README.md --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2e04c08..ab945a5 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ # Codeigniter OAuth 2.0 +## !!! DEPRECATED !!! +**This package is no longer actively maintained. If somebody sends in a pull request with some major security bug +then I'll merge it, but otherwise nothing will be done. Use [thephpleague/oauth2-client](https://github.com/thephpleague/oauth2-client) instead.** + Authorize users with your application in a driver-base fashion meaning one implementation works for multiple OAuth 2 providers. This is only to authenticate onto OAuth2 providers and not to build an OAuth2 service. Note that this Spark ONLY provides the authorization mechanism. There's an example controller below, however in a later version there will be a full controller. @@ -91,4 +95,4 @@ Contribute 3. Write a test which shows that the bug was fixed or that the feature works as expected 4. Send a pull request and bug me until I merge it -[the repository]: https://github.com/philsturgeon/codeigniter-oauth2 \ No newline at end of file +[the repository]: https://github.com/philsturgeon/codeigniter-oauth2