Laravel fortify two factor authentication, enforce confirm code after two factors authentication enabled

Viewed 276

I'd like to ask user input the verification code after the two factors authentication is enabled.

To be more specific, when post /user/two-factor-authentication success, the two factory is enabled, and now user can access resource without provide verification code, so I'd like to ask user confirm the code immediately, but I didn't find any document about this, is it possible to implement it ?

1 Answers

I have approached it by the following code in FortifyServiceProvider.php

use Laravel\Fortify\Features;
use Laravel\Fortify\Actions\AttemptToAuthenticate;
use Laravel\Fortify\Actions\EnsureLoginIsNotThrottled;
use Laravel\Fortify\Actions\PrepareAuthenticatedSession;
use Laravel\Fortify\Actions\RedirectIfTwoFactorAuthenticatable;

    Fortify::authenticateThrough(function (Request $request) {
            return array_filter([
                config('fortify.limiters.login') ? null : EnsureLoginIsNotThrottled::class,
                Features::enabled(Features::twoFactorAuthentication()) ? RedirectIfTwoFactorAuthenticatable::class : null,
                AttemptToenter code hereAuthenticate::class,
                PrepareAuthenticatedSession::class,
            ]);
        });
Related