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' => [ + + + + ], ];