From 810f7283af099ff719d13f7156f5a35826849434 Mon Sep 17 00:00:00 2001 From: Sashagm Date: Wed, 21 Jun 2023 22:50:31 +0500 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=BD=D0=BE=D0=B2=D1=8B=D0=B5=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B8=20=D0=B4=D0=BB=D1=8F=20Fun?= =?UTF-8?q?ctionTrait=20GuardTrait?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Http/Controllers/LoginController.php | 5 ++++- src/Traits/FunctionTrait.php | 19 +++++++++++++++++++ src/Traits/GuardTrait.php | 10 ++++++++++ src/config/socials.php | 8 +++++++- 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/Http/Controllers/LoginController.php b/src/Http/Controllers/LoginController.php index 8d33289..90ef184 100644 --- a/src/Http/Controllers/LoginController.php +++ b/src/Http/Controllers/LoginController.php @@ -18,13 +18,16 @@ class LoginController extends Controller public function redirectToProvider($provider) { + $this->checkGateProvider($provider); + return Socialite::driver($provider)->redirect(); } public function handleProviderCallback($provider) { - + $this->checkGateProvider($provider); + $socialUser = Socialite::driver($provider)->user(); $user = User::where(config('socials.user.email_colum'), $socialUser->getEmail())->first(); diff --git a/src/Traits/FunctionTrait.php b/src/Traits/FunctionTrait.php index e84ef8b..9cfbc51 100644 --- a/src/Traits/FunctionTrait.php +++ b/src/Traits/FunctionTrait.php @@ -31,9 +31,22 @@ private function feedback($method) } foreach ($feedback as $item) { + if (!isset($item['class']) || !isset($item['method'])) { + throw new Exception("Social auth configuration error: class or method not set!"); + } + $class = $item['class']; $method = $item['method']; $params = $item['params']; + + if (!class_exists($class)) { + throw new Exception("Class {$class} not found."); + } + + if (!method_exists($class, $method)) { + throw new Exception("Method {$method} not found in class {$class}."); + } + call_user_func_array([$class, $method], $params); } } @@ -63,6 +76,10 @@ private function cast_fields($socialUser, $provider) private function updateUser($user, $socialUser) { + if (!config('socials.user.auto_update')) { + throw new Exception("Social auth configuration error: auto_update not set!"); + } + if(config('socials.user.auto_update')) { $update = config('socials.user.update_colum'); @@ -81,5 +98,7 @@ private function updateUser($user, $socialUser) { } } + + } \ No newline at end of file diff --git a/src/Traits/GuardTrait.php b/src/Traits/GuardTrait.php index d9d64a0..496f8e5 100644 --- a/src/Traits/GuardTrait.php +++ b/src/Traits/GuardTrait.php @@ -3,6 +3,7 @@ namespace Sashagm\Social\Traits; +use Exception; use App\Models\User; use Illuminate\Database\Eloquent\Relations\MorphToMany; @@ -70,5 +71,14 @@ private function checkProvider($user, $provider) } } + private function checkGateProvider($provider) + { + $allowedProviders = config('socials.providers'); + + if (!in_array($provider, $allowedProviders)) { + throw new Exception('Invalid social provider.'); + } + } + } \ No newline at end of file diff --git a/src/config/socials.php b/src/config/socials.php index 6c5ea63..bb10997 100644 --- a/src/config/socials.php +++ b/src/config/socials.php @@ -122,7 +122,13 @@ ], */ - ], + ], + + 'providers' => [ + + + + ], ];