From 52aebe0f5d48c09443fd41eb280383386ca84741 Mon Sep 17 00:00:00 2001 From: Randy Glenn Aguirre Date: Mon, 27 Oct 2014 22:55:42 +0800 Subject: [PATCH 01/12] Update composer.json --- composer.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 12efc6c..2257855 100644 --- a/composer.json +++ b/composer.json @@ -1,11 +1,15 @@ { - "name": "mmanos/laravel-social", + "name": "chaospower/laravel-social", "description": "A social login package for Laravel 4.", "keywords": ["laravel", "social", "login", "providers", "oauth"], "authors": [ { "name": "Mark Manos", "email": "mark@airpac.com" + }, + { + "name": "Randy Glenn Aguirre", + "email": "rgat.randy@gmail.com" } ], "require": { From 05f910b76912cadb91d820c07edba8bf5fdf5a17 Mon Sep 17 00:00:00 2001 From: Randy Glenn Aguirre Date: Mon, 27 Oct 2014 23:04:04 +0800 Subject: [PATCH 02/12] Update composer.json --- composer.json | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2257855..acada88 100644 --- a/composer.json +++ b/composer.json @@ -12,10 +12,16 @@ "email": "rgat.randy@gmail.com" } ], + "repositories": [ + { + "type": "git", + "url": "git@github.com:ChaosPower/PHPoAuthLib.git" + } + ], "require": { "php": ">=5.4.0", "illuminate/support": ">=4.1", - "lusitanian/oauth": "~0.3" + "chaospower/oauth": "~0.3" }, "autoload": { "classmap": [ From ef417307622b19b7387796513ef035e40444aa22 Mon Sep 17 00:00:00 2001 From: Randy Glenn Aguirre Date: Mon, 27 Oct 2014 23:04:04 +0800 Subject: [PATCH 03/12] Update composer.json --- composer.json | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2257855..964683e 100644 --- a/composer.json +++ b/composer.json @@ -12,10 +12,16 @@ "email": "rgat.randy@gmail.com" } ], + "repositories": [ + { + "type": "git", + "url": "git@github.com:ChaosPower/PHPoAuthLib.git" + } + ], "require": { "php": ">=5.4.0", "illuminate/support": ">=4.1", - "lusitanian/oauth": "~0.3" + "chaospower/PHPoAuthLib": "dev-master" }, "autoload": { "classmap": [ From d13f8eb5d084deb14cc021a534140a8ac65e0f29 Mon Sep 17 00:00:00 2001 From: Randy Glenn Aguirre Date: Sat, 1 Nov 2014 03:45:45 +0800 Subject: [PATCH 04/12] deleted trailing space --- src/Mmanos/Social/SocialServiceProvider.php | 8 +- src/Mmanos/Social/SocialTrait.php | 10 +- src/controllers/SocialController.php | 164 ++++++++++---------- 3 files changed, 91 insertions(+), 91 deletions(-) diff --git a/src/Mmanos/Social/SocialServiceProvider.php b/src/Mmanos/Social/SocialServiceProvider.php index 5a22654..95849cc 100644 --- a/src/Mmanos/Social/SocialServiceProvider.php +++ b/src/Mmanos/Social/SocialServiceProvider.php @@ -12,7 +12,7 @@ class SocialServiceProvider extends ServiceProvider * @var bool */ protected $defer = false; - + /** * Bootstrap the application events. * @@ -21,7 +21,7 @@ class SocialServiceProvider extends ServiceProvider public function boot() { $this->package('mmanos/laravel-social'); - + if ($route = Config::get('laravel-social::route')) { Route::get($route . '/login/{provider}', array( 'as' => 'social-login', @@ -34,7 +34,7 @@ public function boot() Route::controller($route, 'Mmanos\Social\SocialController'); } } - + /** * Register the service provider. * @@ -46,7 +46,7 @@ public function register() return new \Mmanos\Social\Social; }); } - + /** * Get the services provided by the provider. * diff --git a/src/Mmanos/Social/SocialTrait.php b/src/Mmanos/Social/SocialTrait.php index f68e3a5..7b60ccd 100644 --- a/src/Mmanos/Social/SocialTrait.php +++ b/src/Mmanos/Social/SocialTrait.php @@ -11,12 +11,12 @@ public function providers() { return $this->hasMany('Mmanos\Social\Provider'); } - + /** * Return the reqeusted social provider associated with this user. * * @param string $name - * + * * @var Provider */ public function provider($name) @@ -24,16 +24,16 @@ public function provider($name) $providers = $this->providers->filter(function ($provider) use ($name) { return strtolower($provider->provider) == strtolower($name); }); - + return $providers->first(); } - + /** * Return true if this user has connected to the requested social provider. * False, otherwise. * * @param string $name - * + * * @var boolean */ public function hasProvider($name) diff --git a/src/controllers/SocialController.php b/src/controllers/SocialController.php index f9a66e3..76e5d71 100644 --- a/src/controllers/SocialController.php +++ b/src/controllers/SocialController.php @@ -17,7 +17,7 @@ /** * Social providers controller. - * + * * @author Mark Manos */ class SocialController extends Controller @@ -26,7 +26,7 @@ class SocialController extends Controller * Login action. * * @param string $provider - * + * * @return mixed */ public function getLogin($provider = null) @@ -34,26 +34,26 @@ public function getLogin($provider = null) if (empty($provider)) { App::abort(404); } - + $referer = Request::header('referer', '/'); $referer_parts = parse_url($referer); $onerror = array_get($referer_parts, 'path'); if (array_get($referer_parts, 'query')) { $onerror .= '?' . array_get($referer_parts, 'query'); } - + if (!Input::get('code') && !Input::get('oauth_token')) { Session::put('mmanos.social.onsuccess', Input::get('onsuccess', '/')); Session::put('mmanos.social.onerror', Input::get('onerror', $onerror)); } - + if (Auth::check()) { return Redirect::to(Session::pull('mmanos.social.onsuccess', '/')); } - + Session::forget('mmanos.social.pending'); Session::forget('mmanos.social.failed_fields'); - + if (Input::get('denied') || Input::get('error')) { return Redirect::to(Session::pull('mmanos.social.onerror', '/')) ->with( @@ -61,19 +61,19 @@ public function getLogin($provider = null) 'There was a problem logging in to your account (1).' ); } - + $provider = ucfirst($provider); - + try { $service = Social::service($provider); - + if (Config::get('laravel-social::providers.' . strtolower($provider) . '.offline')) { $service->setAccessType('offline'); } } catch (Exception $e) { App::abort(404); } - + if (2 === Social::oauthSpec($provider)) { return $this->oauth2Login($provider, $service); } @@ -81,13 +81,13 @@ public function getLogin($provider = null) return $this->oauth1Login($provider, $service); } } - + /** * Login to an OAuth2 service. * * @param string $provider * @param \OAuth\Common\Service\AbstractService $service - * + * * @return Redirect */ protected function oauth2Login($provider, $service) @@ -102,7 +102,7 @@ protected function oauth2Login($provider, $service) 'There was a problem logging in to your account (2).' ); } - + return $this->processLogin($provider, $service, array( 'token' => $token->getAccessToken(), 'refresh_token' => $token->getRefreshToken(), @@ -110,16 +110,16 @@ protected function oauth2Login($provider, $service) 'extra_params' => $token->getExtraParams(), )); } - + return Redirect::to((string) $service->getAuthorizationUri()); } - + /** * Login to an OAuth1 consumer. * * @param string $provider * @param \OAuth\Common\Service\AbstractService $service - * + * * @return Redirect */ protected function oauth1Login($provider, $service) @@ -138,7 +138,7 @@ protected function oauth1Login($provider, $service) 'There was a problem logging in to your account (3).' ); } - + return $this->processLogin($provider, $service, array( 'token' => $token->getAccessToken(), 'secret' => $token->getAccessTokenSecret(), @@ -147,7 +147,7 @@ protected function oauth1Login($provider, $service) 'extra_params' => $token->getExtraParams(), )); } - + try { // Extra request needed for oauth1 to get a request token. $token = $service->requestRequestToken(); @@ -158,19 +158,19 @@ protected function oauth1Login($provider, $service) 'There was a problem logging in to your account (4).' ); } - + return Redirect::to((string) $service->getAuthorizationUri(array( 'oauth_token' => $token->getRequestToken(), ))); } - + /** * Process the response from a provider login attempt. * * @param string $provider * @param \OAuth\Common\Service\AbstractService $service * @param array $access_token - * + * * @return Redirect */ protected function processLogin($provider, $service, $access_token) @@ -178,7 +178,7 @@ protected function processLogin($provider, $service, $access_token) $user_info_callback = Config::get( 'laravel-social::providers.' . strtolower($provider) . '.fetch_user_info' ); - + if (empty($user_info_callback) || !$user_info_callback instanceof Closure) { return Redirect::to(Session::pull('mmanos.social.onerror', '/')) ->with( @@ -186,11 +186,11 @@ protected function processLogin($provider, $service, $access_token) 'There was a problem logging in to your account (5).' ); } - + try { $user_info = $user_info_callback($service); } catch (Exception $e) {} - + if (empty($user_info) || !is_array($user_info)) { return Redirect::to(Session::pull('mmanos.social.onerror', '/')) ->with( @@ -198,7 +198,7 @@ protected function processLogin($provider, $service, $access_token) 'There was a problem logging in to your account (6).' ); } - + if (empty($user_info['id'])) { return Redirect::to(Session::pull('mmanos.social.onerror', '/')) ->with( @@ -206,18 +206,18 @@ protected function processLogin($provider, $service, $access_token) 'There was a problem logging in to your account (7).' ); } - + $provider_id = array_get($user_info, 'id'); - + $user_provider = Provider::where('provider', strtolower($provider)) ->where('provider_id', $provider_id) ->first(); - + if ($user_provider) { Auth::loginUsingId($user_provider->user_id); return Redirect::to(Session::pull('mmanos.social.onsuccess', '/')); } - + if ($user_validation = Config::get('laravel-social::user_validation')) { if ($user_validation instanceof Closure) { $validator = $user_validation($user_info); @@ -225,7 +225,7 @@ protected function processLogin($provider, $service, $access_token) else { $validator = Validator::make($user_info, (array) $user_validation); } - + if ($validator && $validator->fails()) { Session::put('mmanos.social.pending', array( 'provider' => $provider, @@ -234,12 +234,12 @@ protected function processLogin($provider, $service, $access_token) 'access_token' => $access_token, )); Session::put('mmanos.social.failed_fields', array_keys($validator->failed())); - + return Redirect::action(Config::get('laravel-social::user_failed_validation_redirect')) ->withErrors($validator); } } - + $create_user_callback = Config::get('laravel-social::create_user'); if (empty($create_user_callback) || !$create_user_callback instanceof Closure) { return Redirect::to(Session::pull('mmanos.social.onerror', '/')) @@ -248,7 +248,7 @@ protected function processLogin($provider, $service, $access_token) 'There was a problem logging in to your account (8).' ); } - + $user_id = $create_user_callback($user_info); if (!$user_id || !is_numeric($user_id) || $user_id <= 0) { return Redirect::to(Session::pull('mmanos.social.onerror', '/')) @@ -257,13 +257,13 @@ protected function processLogin($provider, $service, $access_token) 'There was a problem logging in to your account (9).' ); } - + $this->linkProvider($user_id, $provider, $provider_id, $access_token); - + Auth::loginUsingId($user_id); return Redirect::to(Session::pull('mmanos.social.onsuccess', '/')); } - + /** * Complete login action. * @@ -279,7 +279,7 @@ public function getComplete() 'There was a problem logging in to your account (10).' ); } - + $failed_fields = Session::pull('mmanos.social.failed_fields'); if (empty($failed_fields) || !is_array($failed_fields)) { return Redirect::to(Session::pull('mmanos.social.onerror', '/')) @@ -288,13 +288,13 @@ public function getComplete() 'There was a problem logging in to your account (11).' ); } - + return View::make('laravel-social::social.complete', array( 'failed_fields' => $failed_fields, 'info' => array_get($user_data, 'user_info'), )); } - + /** * Handle the complete login form submission. * @@ -310,9 +310,9 @@ public function postComplete() 'There was a problem logging in to your account (12).' ); } - + $user_info = array_merge(array_get($user_data, 'user_info'), Input::all()); - + $user_validation = Config::get('laravel-social::user_validation'); if ($user_validation instanceof Closure) { $validator = $user_validation($user_info); @@ -320,13 +320,13 @@ public function postComplete() else { $validator = Validator::make($user_info, (array) $user_validation); } - + if ($validator->fails()) { return Redirect::action('Mmanos\Social\SocialController@getComplete') ->withInput() ->withErrors($validator); } - + $create_user_callback = Config::get('laravel-social::create_user'); if (empty($create_user_callback) || !$create_user_callback instanceof Closure) { return Redirect::to(Session::pull('mmanos.social.onerror', '/')) @@ -335,7 +335,7 @@ public function postComplete() 'There was a problem logging in to your account (13).' ); } - + $user_id = $create_user_callback($user_info); if (!$user_id || !is_numeric($user_id) || $user_id <= 0) { return Redirect::to(Session::pull('mmanos.social.onerror', '/')) @@ -344,25 +344,25 @@ public function postComplete() 'There was a problem logging in to your account (14).' ); } - + $provider = array_get($user_data, 'provider'); $provider_id = array_get($user_data, 'provider_id'); $access_token = array_get($user_data, 'access_token'); - + $this->linkProvider($user_id, $provider, $provider_id, $access_token); - + Session::forget('mmanos.social.pending'); Session::forget('mmanos.social.failed_fields'); - + Auth::loginUsingId($user_id); return Redirect::to(Session::pull('mmanos.social.onsuccess', '/')); } - + /** * Connect action. * * @param string $provider - * + * * @return mixed */ public function getConnect($provider = null) @@ -370,19 +370,19 @@ public function getConnect($provider = null) if (empty($provider)) { App::abort(404); } - + $referer = Request::header('referer', '/'); $referer_parts = parse_url($referer); $onboth = array_get($referer_parts, 'path'); if (array_get($referer_parts, 'query')) { $onboth .= '?' . array_get($referer_parts, 'query'); } - + if (!Input::get('code') && !Input::get('oauth_token')) { Session::put('mmanos.social.onsuccess', Input::get('onsuccess', $onboth)); Session::put('mmanos.social.onerror', Input::get('onerror', $onboth)); } - + if (!Auth::check()) { return Redirect::to(Session::pull('mmanos.social.onerror', '/')) ->with( @@ -390,7 +390,7 @@ public function getConnect($provider = null) 'There was a problem connecting your account (1).' ); } - + if (Input::get('denied') || Input::get('error')) { return Redirect::to(Session::pull('mmanos.social.onerror', '/')) ->with( @@ -398,19 +398,19 @@ public function getConnect($provider = null) 'There was a problem connecting your account (2).' ); } - + $provider = ucfirst($provider); - + try { $service = Social::service($provider); - + if (Config::get('laravel-social::providers.' . strtolower($provider) . '.offline')) { $service->setAccessType('offline'); } } catch (Exception $e) { App::abort(404); } - + if (2 === Social::oauthSpec($provider)) { return $this->oauth2Connect($provider, $service); } @@ -418,13 +418,13 @@ public function getConnect($provider = null) return $this->oauth1Connect($provider, $service); } } - + /** * Login to an OAuth2 service. * * @param string $provider * @param \OAuth\Common\Service\AbstractService $service - * + * * @return Redirect */ protected function oauth2Connect($provider, $service) @@ -439,21 +439,21 @@ protected function oauth2Connect($provider, $service) 'There was a problem connecting your account (3).' ); } - + return $this->processConnect($provider, $service, array( 'token' => $token->getAccessToken(), )); } - + return Redirect::to((string) $service->getAuthorizationUri()); } - + /** * Login to an OAuth1 consumer. * * @param string $provider * @param \OAuth\Common\Service\AbstractService $service - * + * * @return Redirect */ protected function oauth1Connect($provider, $service) @@ -472,13 +472,13 @@ protected function oauth1Connect($provider, $service) 'There was a problem connecting your account (4).' ); } - + return $this->processConnect($provider, $service, array( 'token' => $token->getAccessToken(), 'secret' => $token->getAccessTokenSecret(), )); } - + try { // Extra request needed for oauth1 to get a request token. $token = $service->requestRequestToken(); @@ -489,19 +489,19 @@ protected function oauth1Connect($provider, $service) 'There was a problem connecting your account (5).' ); } - + return Redirect::to((string) $service->getAuthorizationUri(array( 'oauth_token' => $token->getRequestToken(), ))); } - + /** * Process the response from a provider connect attempt. * * @param string $provider * @param \OAuth\Common\Service\AbstractService $service * @param array $access_token - * + * * @return Redirect */ protected function processConnect($provider, $service, $access_token) @@ -509,7 +509,7 @@ protected function processConnect($provider, $service, $access_token) $user_info_callback = Config::get( 'laravel-social::providers.' . strtolower($provider) . '.fetch_user_info' ); - + if (empty($user_info_callback) || !$user_info_callback instanceof Closure) { return Redirect::to(Session::pull('mmanos.social.onerror', '/')) ->with( @@ -517,11 +517,11 @@ protected function processConnect($provider, $service, $access_token) 'There was a problem connecting your account (6).' ); } - + try { $user_info = $user_info_callback($service); } catch (Exception $e) {} - + if (empty($user_info) || !is_array($user_info)) { return Redirect::to(Session::pull('mmanos.social.onerror', '/')) ->with( @@ -529,7 +529,7 @@ protected function processConnect($provider, $service, $access_token) 'There was a problem connecting your account (7).' ); } - + if (empty($user_info['id'])) { return Redirect::to(Session::pull('mmanos.social.onerror', '/')) ->with( @@ -537,13 +537,13 @@ protected function processConnect($provider, $service, $access_token) 'There was a problem connecting your account (8).' ); } - + $provider_id = array_get($user_info, 'id'); - + $user_provider = Provider::where('provider', strtolower($provider)) ->where('provider_id', $provider_id) ->first(); - + if ($user_provider) { if ($user_provider->user_id != Auth::id()) { return Redirect::to(Session::pull('mmanos.social.onerror', '/')) @@ -552,21 +552,21 @@ protected function processConnect($provider, $service, $access_token) 'There was a problem connecting your account (9).' ); } - + $user_provider->access_token = $access_token; $user_provider->save(); } else { $this->linkProvider(Auth::id(), $provider, $provider_id, $access_token); } - + return Redirect::to(Session::pull('mmanos.social.onsuccess', '/')) ->with( Config::get('laravel-social::success_flash_var'), 'You have successfully connected your account.' ); } - + /** * Link the give user to the given provider. * @@ -574,7 +574,7 @@ protected function processConnect($provider, $service, $access_token) * @param string $provider * @param integer $provider_id * @param array $access_token - * + * * @return Provider */ protected function linkProvider($user_id, $provider, $provider_id, $access_token) @@ -585,7 +585,7 @@ protected function linkProvider($user_id, $provider, $provider_id, $access_token $user_provider->provider_id = $provider_id; $user_provider->access_token = $access_token; $user_provider->save(); - + return $user_provider; } } From aab2e167e3e78561aaf71f90d28a98767e6731ab Mon Sep 17 00:00:00 2001 From: Randy Glenn Aguirre Date: Sat, 1 Nov 2014 03:45:57 +0800 Subject: [PATCH 05/12] switched to packagist --- composer.json | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/composer.json b/composer.json index 964683e..4b78a25 100644 --- a/composer.json +++ b/composer.json @@ -12,16 +12,10 @@ "email": "rgat.randy@gmail.com" } ], - "repositories": [ - { - "type": "git", - "url": "git@github.com:ChaosPower/PHPoAuthLib.git" - } - ], "require": { "php": ">=5.4.0", "illuminate/support": ">=4.1", - "chaospower/PHPoAuthLib": "dev-master" + "chaospower/phpoauthlib": "0.1.*@dev" }, "autoload": { "classmap": [ From 9baed43e7f0f95a93ceb399cb5988d2741a19bcd Mon Sep 17 00:00:00 2001 From: Randy Glenn Aguirre Date: Wed, 19 Nov 2014 10:42:58 +0800 Subject: [PATCH 06/12] Added service api version --- src/Mmanos/Social/Social.php | 37 +++++++++++++++++++----------------- src/config/config.php | 1 + 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/Mmanos/Social/Social.php b/src/Mmanos/Social/Social.php index ec0cd3a..09c996e 100644 --- a/src/Mmanos/Social/Social.php +++ b/src/Mmanos/Social/Social.php @@ -15,14 +15,14 @@ class Social * @var \OAuth\ServiceFactory */ protected $factory; - + /** * The Service Storage instance. * * @var \OAuth\Common\Storage\TokenStorageInterface */ protected $storage; - + /** * Create a new Social instance. * @@ -33,59 +33,62 @@ public function __construct() $this->factory = new ServiceFactory; $this->storage = new Session; } - + /** * Return an instance of the requested service. * * @param string $provider * @param string $url * @param array $scope - * + * * @return \OAuth\Common\Service\AbstractService * @throws \Exception */ - public function service($provider, $url = null, $scope = null) + public function service($provider, $url = null, $scope = null, $apiVersion = null) { $info = Config::get('laravel-social::providers.' . strtolower($provider)); - + if (empty($info) || !is_array($info)) { throw new Exception('Missing configuration details for Social service: ' . $provider); } - - $client_id = array_get($info, 'client_id'); - $client_secret = array_get($info, 'client_secret'); - $scope = is_null($scope) ? array_get($info, 'scope') : $scope; - + + $client_id = array_get($info, 'client_id'); + $client_secret = array_get($info, 'client_secret'); + $scope = is_null($scope) ? array_get($info, 'scope') : $scope; + $apiVersion = is_null($apiVersion) ? array_get($info,'api_version') : $apiVersion; + if (empty($client_id) || empty($client_secret)) { throw new Exception('Missing client id/secret for Social service: ' . $provider); } - + return $this->factory->createService( ucfirst($provider), new Credentials($client_id, $client_secret, $url ?: URL::current()), $this->storage, - $scope + $scope, + null, + $apiVersion ); } - + /** * Return the OAuth spec used by the given service provider. * * @param string $provider - * + * * @return integer */ public function oauthSpec($provider) { $service = $this->service($provider); - + if (false !== stristr(get_class($service), 'OAuth1')) { return 1; } else if (false !== stristr(get_class($service), 'OAuth2')) { return 2; } - + return null; } } diff --git a/src/config/config.php b/src/config/config.php index a591630..1f1b6cf 100644 --- a/src/config/config.php +++ b/src/config/config.php @@ -41,6 +41,7 @@ 'client_id' => '', 'client_secret' => '', 'scope' => array('email'), + 'api_version' => 'v2.2', 'fetch_user_info' => function ($service) { $result = json_decode($service->request('/me'), true); return array( From 7b9ee48a54d2058824cad161fd5c8e485fe87566 Mon Sep 17 00:00:00 2001 From: Randy Glenn Aguirre Date: Wed, 19 Nov 2014 10:43:47 +0800 Subject: [PATCH 07/12] deleted trailing spaces --- ..._laravel_social_create_providers_table.php | 8 ++--- src/models/Provider.php | 36 +++++++++---------- src/views/social/complete.blade.php | 8 ++--- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/migrations/2014_09_04_000000_laravel_social_create_providers_table.php b/src/migrations/2014_09_04_000000_laravel_social_create_providers_table.php index 5f174b2..b06912d 100644 --- a/src/migrations/2014_09_04_000000_laravel_social_create_providers_table.php +++ b/src/migrations/2014_09_04_000000_laravel_social_create_providers_table.php @@ -13,7 +13,7 @@ class LaravelSocialCreateProvidersTable extends Migration public function up() { $table_name = Config::get('laravel-social::table', 'user_providers'); - + Schema::create($table_name, function ($table) { $table->increments('id'); $table->integer('user_id'); @@ -21,12 +21,12 @@ public function up() $table->string('provider_id'); $table->text('access_token'); $table->timestamps(); - + $table->unique(array('provider', 'provider_id')); $table->index(array('user_id', 'provider')); }); } - + /** * Reverse the migrations. * @@ -35,7 +35,7 @@ public function up() public function down() { $table_name = Config::get('laravel-social::table', 'user_providers'); - + Schema::drop($table_name); } } \ No newline at end of file diff --git a/src/models/Provider.php b/src/models/Provider.php index 4c48aad..6df988c 100644 --- a/src/models/Provider.php +++ b/src/models/Provider.php @@ -10,28 +10,28 @@ class Provider extends Model { protected $hidden = array('user_id', 'updated_at'); protected $guarded = array('id'); - + public function getTable() { return Config::get('laravel-social::table', 'user_providers'); } - + public function getAccessTokenAttribute($value) { return json_decode(Crypt::decrypt($value), true); } - + public function setAccessTokenAttribute($value) { $this->attributes['access_token'] = Crypt::encrypt(json_encode($value)); } - + public function request($path, $method = 'GET', $body = null, array $extra_headers = array()) { $access_token = $this->access_token; - + $service = Facades\Social::service($this->provider); - + if (2 === Facades\Social::oauthSpec($this->provider)) { $token = new StdOAuth2Token; $token->setAccessToken(array_get($access_token, 'token')); @@ -41,26 +41,26 @@ public function request($path, $method = 'GET', $body = null, array $extra_heade $token->setAccessToken(array_get($access_token, 'token')); $token->setAccessTokenSecret(array_get($access_token, 'secret')); } - + $service->getStorage()->storeAccessToken(ucfirst($this->provider), $token); - + try { return $service->request($path, $method, $body, $extra_headers); } catch (\OAuth\Common\Http\Exception\TokenResponseException $e) { if ($this->refreshAccessToken()) { return $service->request($path, $method, $body, $extra_headers); } - + throw $e; } } - + public function refreshAccessToken() { $access_token = $this->access_token; - + $service = Facades\Social::service($this->provider); - + if (2 === Facades\Social::oauthSpec($this->provider)) { $token = new StdOAuth2Token; $token->setAccessToken(array_get($access_token, 'token')); @@ -72,19 +72,19 @@ public function refreshAccessToken() $token->setAccessTokenSecret(array_get($access_token, 'secret')); $token->setRefreshToken(array_get($access_token, 'refresh_token')); } - + $service->getStorage()->storeAccessToken(ucfirst($this->provider), $token); - + try { $new_token = $service->refreshAccessToken($token); } catch (\Exception $e) { return false; } - + if (!$new_token->getAccessToken()) { return false; } - + $access_token['token'] = $new_token->getAccessToken(); if ($new_token->getEndOfLife()) { $access_token['end_of_life'] = $new_token->getEndOfLife(); @@ -95,10 +95,10 @@ public function refreshAccessToken() if (2 !== Facades\Social::oauthSpec($this->provider) && $new_token->getAccessTokenSecret()) { $access_token['secret'] = $new_token->getAccessTokenSecret(); } - + $this->access_token = $access_token; $this->save(); - + return true; } } diff --git a/src/views/social/complete.blade.php b/src/views/social/complete.blade.php index f6b63a0..80a0709 100644 --- a/src/views/social/complete.blade.php +++ b/src/views/social/complete.blade.php @@ -2,23 +2,23 @@

Please complete your profile...

- + {{ Form::open(array('action' => 'Mmanos\Social\SocialController@postComplete')) }}
@foreach ($failed_fields as $idx => $field)
{{ Form::label($field, ucwords(str_replace(array('-', '_'), ' ', $field))) }} - + @if ($idx === 0) {{ Form::text($field, Input::old($field, array_get($info, $field)), array('autofocus' => 'autofocus', 'class' => 'form-control')) }} @else {{ Form::text($field, Input::old($field, array_get($info, $field)), array('class' => 'form-control')) }} @endif - + {{ $errors->first($field, ':message') }}
@endforeach - +
{{ Form::submit('Save', array('class' => 'btn btn-primary')) }}
From 9954ce526276bc42fd7dcbd751f75ceb2e1511a8 Mon Sep 17 00:00:00 2001 From: Randy Glenn Aguirre Date: Fri, 28 Nov 2014 11:23:51 +0800 Subject: [PATCH 08/12] changed apiVersion to snake case --- src/Mmanos/Social/Social.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Mmanos/Social/Social.php b/src/Mmanos/Social/Social.php index 09c996e..14803d0 100644 --- a/src/Mmanos/Social/Social.php +++ b/src/Mmanos/Social/Social.php @@ -44,7 +44,7 @@ public function __construct() * @return \OAuth\Common\Service\AbstractService * @throws \Exception */ - public function service($provider, $url = null, $scope = null, $apiVersion = null) + public function service($provider, $url = null, $scope = null, $api_version = null) { $info = Config::get('laravel-social::providers.' . strtolower($provider)); @@ -55,7 +55,7 @@ public function service($provider, $url = null, $scope = null, $apiVersion = nul $client_id = array_get($info, 'client_id'); $client_secret = array_get($info, 'client_secret'); $scope = is_null($scope) ? array_get($info, 'scope') : $scope; - $apiVersion = is_null($apiVersion) ? array_get($info,'api_version') : $apiVersion; + $api_version = is_null($api_version) ? array_get($info,'api_version') : $api_version; if (empty($client_id) || empty($client_secret)) { throw new Exception('Missing client id/secret for Social service: ' . $provider); @@ -67,7 +67,7 @@ public function service($provider, $url = null, $scope = null, $apiVersion = nul $this->storage, $scope, null, - $apiVersion + $api_version ); } From 1d9549024411313776d3c44e413ae78c5dede21c Mon Sep 17 00:00:00 2001 From: Randy Glenn Aguirre Date: Thu, 18 Dec 2014 08:45:49 +0800 Subject: [PATCH 09/12] switched to dev-master --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 4b78a25..6ad89c3 100644 --- a/composer.json +++ b/composer.json @@ -14,8 +14,8 @@ ], "require": { "php": ">=5.4.0", - "illuminate/support": ">=4.1", - "chaospower/phpoauthlib": "0.1.*@dev" + "illuminate/support": "~4|~5", + "chaospower/phpoauthlib": "dev-master" }, "autoload": { "classmap": [ From b994234240a8b8f2338fd244e875aeeaa9e9b090 Mon Sep 17 00:00:00 2001 From: Randy Glenn Aguirre Date: Thu, 18 Dec 2014 09:26:46 +0800 Subject: [PATCH 10/12] changed reference to 0.3 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6ad89c3..9fdc383 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "require": { "php": ">=5.4.0", "illuminate/support": "~4|~5", - "chaospower/phpoauthlib": "dev-master" + "chaospower/phpoauthlib": "~0.3" }, "autoload": { "classmap": [ From 566ab8cf364003c6ffe11fac651e847866e9242a Mon Sep 17 00:00:00 2001 From: Randy Glenn Aguirre Date: Thu, 18 Dec 2014 13:29:29 +0800 Subject: [PATCH 11/12] changed to 0.3.6 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9fdc383..bd9d8ea 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "require": { "php": ">=5.4.0", "illuminate/support": "~4|~5", - "chaospower/phpoauthlib": "~0.3" + "chaospower/phpoauthlib": "~0.3.6" }, "autoload": { "classmap": [ From 5704beb8eb2ba2335a412f91639786a1499b7ab6 Mon Sep 17 00:00:00 2001 From: Randy Glenn Aguirre Date: Thu, 18 Dec 2014 13:37:48 +0800 Subject: [PATCH 12/12] switched to 0.4 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index bd9d8ea..923ffd3 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "require": { "php": ">=5.4.0", "illuminate/support": "~4|~5", - "chaospower/phpoauthlib": "~0.3.6" + "chaospower/phpoauthlib": "~0.4" }, "autoload": { "classmap": [