Skip to content

[1.x] Only use two factor action when enabled #127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Http/Controllers/AuthenticatedSessionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Laravel\Fortify\Contracts\LoginResponse;
use Laravel\Fortify\Contracts\LoginViewResponse;
use Laravel\Fortify\Contracts\LogoutResponse;
use Laravel\Fortify\Features;
use Laravel\Fortify\Fortify;
use Laravel\Fortify\Http\Requests\LoginRequest;

Expand Down Expand Up @@ -82,7 +83,7 @@ protected function loginPipeline(LoginRequest $request)

return (new Pipeline(app()))->send($request)->through(array_filter([
config('fortify.limiters.login') ? null : EnsureLoginIsNotThrottled::class,
RedirectIfTwoFactorAuthenticatable::class,
Features::enabled(Features::twoFactorAuthentication()) ? RedirectIfTwoFactorAuthenticatable::class : null,
AttemptToAuthenticate::class,
PrepareAuthenticatedSession::class,
]));
Expand Down
32 changes: 32 additions & 0 deletions tests/AuthenticatedSessionControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Schema;
use Laravel\Fortify\Contracts\LoginViewResponse;
use Laravel\Fortify\Features;
use Laravel\Fortify\FortifyServiceProvider;
use Laravel\Fortify\LoginRateLimiter;
use Laravel\Fortify\TwoFactorAuthenticatable;
Expand Down Expand Up @@ -70,6 +71,37 @@ public function test_user_is_redirected_to_challenge_when_using_two_factor_authe
$response->assertRedirect('/two-factor-challenge');
}

public function test_user_can_authenticate_when_two_factor_challenge_is_disabled()
{
app('config')->set('auth.providers.users.model', TestTwoFactorAuthenticationSessionUser::class);

$features = app('config')->get('fortify.features');

unset($features[array_search(Features::twoFactorAuthentication(), $features)]);

app('config')->set('fortify.features', $features);

$this->loadLaravelMigrations(['--database' => 'testbench']);

Schema::table('users', function ($table) {
$table->text('two_factor_secret')->nullable();
});

TestTwoFactorAuthenticationSessionUser::forceCreate([
'name' => 'Taylor Otwell',
'email' => '[email protected]',
'password' => bcrypt('secret'),
'two_factor_secret' => 'test-secret',
]);

$response = $this->withoutExceptionHandling()->post('/login', [
'email' => '[email protected]',
'password' => 'secret',
]);

$response->assertRedirect('/home');
}

public function test_validation_exception_returned_on_failure()
{
$this->loadLaravelMigrations(['--database' => 'testbench']);
Expand Down