Skip to content

Commit 81bb09f

Browse files
authored
Add option to disable password login (#2318)
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
1 parent dcba4a9 commit 81bb09f

3 files changed

Lines changed: 22 additions & 1 deletion

File tree

app/Filament/Pages/Auth/Login.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Filament\Schemas\Components\Component;
1414
use Filament\Schemas\Schema;
1515
use Filament\Support\Colors\Color;
16+
use Filament\Support\Enums\Alignment;
1617
use Illuminate\Validation\ValidationException;
1718

1819
class Login extends BaseLogin
@@ -32,6 +33,12 @@ public function boot(OAuthService $oauthService, CaptchaService $captchaService,
3233

3334
public function form(Schema $schema): Schema
3435
{
36+
if (config('auth.disable_password_login', false)) {
37+
return $schema->components([
38+
$this->getOAuthFormComponent(),
39+
]);
40+
}
41+
3542
$components = [
3643
$this->getLoginFormComponent(),
3744
$this->getPasswordFormComponent(),
@@ -108,11 +115,22 @@ protected function getOAuthFormComponent(): Component
108115
->url(route('auth.oauth.redirect', ['driver' => $id], false));
109116
}
110117

111-
return Actions::make($actions);
118+
return Actions::make($actions)->alignment(fn () => config('auth.disable_password_login', false) ? Alignment::Center : null);
119+
}
120+
121+
protected function getFormActions(): array
122+
{
123+
return config('auth.disable_password_login', false) ? [] : parent::getFormActions();
112124
}
113125

114126
protected function getCredentialsFromFormData(array $data): array
115127
{
128+
if (config('auth.disable_password_login', false)) {
129+
throw ValidationException::withMessages([
130+
'data.login' => trans('auth.password_login_disabled'),
131+
]);
132+
}
133+
116134
$loginType = filter_var($data['login'], FILTER_VALIDATE_EMAIL) ? 'email' : 'username';
117135

118136
return [

config/auth.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
return [
44

5+
'disable_password_login' => env('AUTH_DISABLE_PASSWORD_LOGIN', false),
6+
57
'lockout' => [
68
'time' => 2,
79
'attempts' => 3,

lang/en/auth.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@
2020
'password' => 'The provided password is incorrect.',
2121
'throttle' => 'Too many login attempts. Please try again in :seconds seconds.',
2222
'2fa_must_be_enabled' => 'The administrator has required that 2-Factor Authentication must be enabled for your account in order to use the Panel.',
23+
'password_login_disabled' => 'Password login is disabled. Please use an OAuth provider to sign in.',
2324

2425
];

0 commit comments

Comments
 (0)