diff --git a/app/Filament/Pages/Auth/Login.php b/app/Filament/Pages/Auth/Login.php index 4ee735fa17..17fa999a38 100644 --- a/app/Filament/Pages/Auth/Login.php +++ b/app/Filament/Pages/Auth/Login.php @@ -13,6 +13,7 @@ use Filament\Schemas\Components\Component; use Filament\Schemas\Schema; use Filament\Support\Colors\Color; +use Filament\Support\Enums\Alignment; use Illuminate\Validation\ValidationException; class Login extends BaseLogin @@ -32,6 +33,12 @@ public function boot(OAuthService $oauthService, CaptchaService $captchaService, public function form(Schema $schema): Schema { + if (config('auth.disable_password_login', false)) { + return $schema->components([ + $this->getOAuthFormComponent(), + ]); + } + $components = [ $this->getLoginFormComponent(), $this->getPasswordFormComponent(), @@ -108,11 +115,22 @@ protected function getOAuthFormComponent(): Component ->url(route('auth.oauth.redirect', ['driver' => $id], false)); } - return Actions::make($actions); + return Actions::make($actions)->alignment(fn () => config('auth.disable_password_login', false) ? Alignment::Center : null); + } + + protected function getFormActions(): array + { + return config('auth.disable_password_login', false) ? [] : parent::getFormActions(); } protected function getCredentialsFromFormData(array $data): array { + if (config('auth.disable_password_login', false)) { + throw ValidationException::withMessages([ + 'data.login' => trans('auth.password_login_disabled'), + ]); + } + $loginType = filter_var($data['login'], FILTER_VALIDATE_EMAIL) ? 'email' : 'username'; return [ diff --git a/config/auth.php b/config/auth.php index eefb4ede4f..3c2a76ef7c 100644 --- a/config/auth.php +++ b/config/auth.php @@ -2,6 +2,8 @@ return [ + 'disable_password_login' => env('AUTH_DISABLE_PASSWORD_LOGIN', false), + 'lockout' => [ 'time' => 2, 'attempts' => 3, diff --git a/lang/en/auth.php b/lang/en/auth.php index d88b093972..6c5cf6fda7 100644 --- a/lang/en/auth.php +++ b/lang/en/auth.php @@ -20,5 +20,6 @@ 'password' => 'The provided password is incorrect.', 'throttle' => 'Too many login attempts. Please try again in :seconds seconds.', '2fa_must_be_enabled' => 'The administrator has required that 2-Factor Authentication must be enabled for your account in order to use the Panel.', + 'password_login_disabled' => 'Password login is disabled. Please use an OAuth provider to sign in.', ];