diff --git a/changelog.md b/changelog.md index c113b0b..7adbc9b 100755 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,10 @@ # Changelog All notable changes to `GoogleAuthenticator` will be documented in this file. +## Version 4.2.0 +- Added support for Laravel 10 +- Added return types +- Removed support for Laravel 8 ## Version 4.1.3 - Added banner image in readme ## Version 4.1.2 @@ -10,7 +14,7 @@ All notable changes to `GoogleAuthenticator` will be documented in this file. ## Version 4.1.0 - Updated version illumninate/support to use Laravel 8 or 9 - Updated auth templates with new format from Laravel + google login button -- Removed Laravel support for version 6 and 7 +- Removed Laravel support for version 6 and 7 - Removed google/apiclient ## Version 4.0.0 ### Updated @@ -48,7 +52,7 @@ All notable changes to `GoogleAuthenticator` will be documented in this file. ## Version 3.0.1 ### Changed - Fixed markdown typos -- Removed statik.be from roles array in config file +- Removed statik.be from roles array in config file ## Version 3.0.0 ### Changed @@ -86,7 +90,7 @@ All notable changes to `GoogleAuthenticator` will be documented in this file. - Added names for routes & use them in overwritten auth views ### Changed - Updated packages to work with laravel 6 -- Cleaned up some code +- Cleaned up some code ## Version 1.0.9 ### Added @@ -129,4 +133,4 @@ All notable changes to `GoogleAuthenticator` will be documented in this file. ## Version 1.0 ### Added -- Everything +- Everything \ No newline at end of file diff --git a/composer.json b/composer.json index 137588d..7629f16 100755 --- a/composer.json +++ b/composer.json @@ -16,9 +16,9 @@ "homepage": "https://github.com/statikbe/laravel-google-authenticate", "keywords": ["Laravel", "google", "authenticate", "socialite"], "require": { - "illuminate/support": "^8.0|^9.0", - "illuminate/routing": "^8.0|^9.0", - "laravel/socialite": "^5.5" + "illuminate/support": "^9.0|^10.0", + "illuminate/routing": "^9.0|^10.0", + "laravel/socialite": "^5.6" }, "suggest": { "doctrine/dbal": "If you are using the provided migration you will need doctrine/dbal." diff --git a/src/GoogleAuthenticateController.php b/src/GoogleAuthenticateController.php index 25fff8d..f26f432 100755 --- a/src/GoogleAuthenticateController.php +++ b/src/GoogleAuthenticateController.php @@ -2,10 +2,11 @@ namespace Statikbe\GoogleAuthenticate; +use App\Models\User; +use Illuminate\Http\RedirectResponse; use Illuminate\Routing\Controller; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Redirect; -use Illuminate\Support\Str; use Laravel\Socialite\AbstractUser; use Laravel\Socialite\Facades\Socialite; use Laravel\Socialite\Two\InvalidStateException; @@ -29,7 +30,7 @@ class GoogleAuthenticateController extends Controller * * @var string */ - protected $redirectTo = '/'; + protected mixed $redirectTo = '/'; const GOOGLE_VALUES = [ 'name', @@ -61,16 +62,16 @@ public function __construct() /** * Redirect the user to the Google authentication page. * - * @return \Illuminate\Http\Response + * @return RedirectResponse */ - public function redirectToProvider() + public function redirectToProvider(): RedirectResponse { request()->session()->flash('googleLoginUrl', url()->previous()); return Socialite::driver('google')->scopes(['openid', 'profile', 'email'])->redirect(); } - public function handleProviderCallback() + public function handleProviderCallback(): RedirectResponse { $loginUrl = session('googleLoginUrl') ?? '/'; @@ -97,7 +98,7 @@ public function handleProviderCallback() * @return User * @throws GoogleAuthenticationException */ - private function findOrCreate(AbstractUser $googleUser, string $provider) + private function findOrCreate(AbstractUser $googleUser, string $provider): User { if (isset($googleUser->email)) { //make userFillableArray @@ -115,7 +116,7 @@ private function findOrCreate(AbstractUser $googleUser, string $provider) //If the disabled array is filled we check the domain against it $domainsToIgnore = $domains['disabled'] ?? null; if ($domainsToIgnore) { - if (in_array($emailDomain, $domainsToIgnore)) { + if (in_array($emailDomain, $domainsToIgnore, true)) { throw new GoogleAuthenticationException(); } } @@ -123,7 +124,7 @@ private function findOrCreate(AbstractUser $googleUser, string $provider) //If the allowed array is filled we check the domain against it $domainsToValidate = $domains['allowed'] ?? null; if (!empty($domainsToValidate)) { - if (in_array($emailDomain, $domainsToValidate)) { + if (in_array($emailDomain, $domainsToValidate, true)) { return $this->createUser($userData); } throw new GoogleAuthenticationException(); @@ -141,7 +142,7 @@ private function findOrCreate(AbstractUser $googleUser, string $provider) * @param AbstractUser $user * @return array $data */ - private function fillUserData(AbstractUser $user) + private function fillUserData(AbstractUser $user): array { //get user table columns $columns = config('google-authenticate.user_columns', []); @@ -161,12 +162,11 @@ private function fillUserData(AbstractUser $user) /** * @param array $userData - * @param Role $roleModel * @return User $user */ - private function createUser($userData) + private function createUser(array $userData): User { - //search for possible user with this email but without google provider + //search for possible user with this email but without Google provider $user = $this->userModel::where('email', $userData['email'])->whereNull('provider_id')->first(); if ($user) { //filling found user @@ -187,9 +187,9 @@ private function createUser($userData) /** * @param array $values - * @param $user Socialite user object + * @param $user user object */ - private function checkForGoogleData(&$values, $user) + private function checkForGoogleData(array &$values, $user): void { //loop values provided from configInvalidStateException foreach ($values as $key => $value) { @@ -201,10 +201,9 @@ private function checkForGoogleData(&$values, $user) } //if value found in google_values array, return it's google value - if (in_array($value, self::GOOGLE_VALUES)) { + if (in_array($value, self::GOOGLE_VALUES, true)) { $values[$key] = $user[$value]; - continue; } } } -} +} \ No newline at end of file diff --git a/src/GoogleAuthenticateServiceProvider.php b/src/GoogleAuthenticateServiceProvider.php index fc14fab..25d00a6 100755 --- a/src/GoogleAuthenticateServiceProvider.php +++ b/src/GoogleAuthenticateServiceProvider.php @@ -11,18 +11,18 @@ class GoogleAuthenticateServiceProvider extends ServiceProvider * * @return void */ - public function boot() + public function boot(): void { //$this->loadViewsFrom(__DIR__.'/../resources/views', 'google-authenticate'); $this->publishes([ - __DIR__.'/../database/migrations/add_google_provider_to_user_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_add_google_provider_to_user_table.php'), + __DIR__ . '/../database/migrations/add_google_provider_to_user_table.php.stub' => database_path('migrations/' . date('Y_m_d_His', time()) . '_add_google_provider_to_user_table.php'), ], 'migrations'); //loaders - $this->loadRoutesFrom(__DIR__.'/routes.php'); + $this->loadRoutesFrom(__DIR__ . '/routes.php'); - $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'google-authenticate'); + $this->loadTranslationsFrom(__DIR__ . '/../resources/lang', 'google-authenticate'); // Publishing is only necessary when using the CLI: if ($this->app->runningInConsole()) { @@ -35,10 +35,10 @@ public function boot() * * @return void */ - public function register() + public function register(): void { $this->mergeConfigFrom( - __DIR__.'/config/google-authenticate.php', 'google-authenticate' + __DIR__ . '/config/google-authenticate.php', 'google-authenticate' ); // Register the service the package provides. @@ -52,7 +52,7 @@ public function register() * * @return array */ - public function provides() + public function provides(): array { return ['GoogleAuthenticate']; } @@ -62,25 +62,25 @@ public function provides() * * @return void */ - protected function bootForConsole() + protected function bootForConsole(): void { // Publishing the views $this->publishes([ - __DIR__.'/../resources/views' => resource_path('views/vendor/google-authenticate'), + __DIR__ . '/../resources/views' => resource_path('views/vendor/google-authenticate'), ], 'views'); //publish the translations $langPath = 'vendor/google-authenticate'; $langPath = (function_exists('lang_path')) ? lang_path($langPath) - : resource_path('lang/'.$langPath); + : resource_path('lang/' . $langPath); $this->publishes([ - __DIR__.'/../resources/lang' => $langPath, + __DIR__ . '/../resources/lang' => $langPath, ], 'lang'); //publishes config file $this->publishes([ - __DIR__.'/config/google-authenticate.php' => config_path('google-authenticate.php'), + __DIR__ . '/config/google-authenticate.php' => config_path('google-authenticate.php'), ], 'config'); } -} +} \ No newline at end of file diff --git a/src/Traits/HasGoogleAuth.php b/src/Traits/HasGoogleAuth.php index e2c5837..0e8d690 100755 --- a/src/Traits/HasGoogleAuth.php +++ b/src/Traits/HasGoogleAuth.php @@ -4,21 +4,21 @@ trait HasGoogleAuth { - + /** * The attributes that are needed for Google Auth * @var array */ - protected $auth_fillable = [ + protected array $auth_fillable = [ 'provider', 'provider_id' ]; - - - public function getFillable() + + + public function getFillable(): array { - + return array_merge($this->fillable, $this->auth_fillable); } - -} \ No newline at end of file + +}