PHP code example of gabrielesbaiz / nova-two-factor

1. Go to this page and download the library: Download gabrielesbaiz/nova-two-factor library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

gabrielesbaiz / nova-two-factor example snippets


use Laravel\Fortify\Features;

Nova::fortify()->features([
    Features::twoFactorAuthentication(['confirm' => true, 'confirmPassword' => true]),
]);

use Gabrielesbaiz\NovaTwoFactor\Concerns\HasTwoFactorAuthentication;

class User extends Authenticatable
{
    use HasTwoFactorAuthentication;
}

use Gabrielesbaiz\NovaTwoFactor\NovaTwoFactor;

public function tools(): array
{
    return [
        NovaTwoFactor::make(),
    ];
}

use Laravel\Fortify\Features;

Nova::fortify()->features([
    Features::updatePasswords(),
    Features::twoFactorAuthentication(['confirm' => false, 'confirmPassword' => false]),
]);

// config/nova-two-factor.php
'fortify' => [
    'supersede_challenge' => true,
],

// config/nova-two-factor.php
'ui' => [
    'show_method_tradeoffs' => false,
],

// config/nova-two-factor.php
'methods' => [
    'webauthn' => [
        'enabled' => true,
        'relying_party' => ['id' => null], // defaults to the host of app.url
        'origins' => [],                   // defaults to [app.url]
    ],
],

NovaTwoFactor::make()->enforce('

NovaTwoFactor::make()->

'enforcement' => ['gate' => '

NovaTwoFactor::make()->protectWithStepUp('users.destroy', [
    'DELETE nova-api/users/*',
]);

Route::delete('/danger', DangerController::class)
    ->middleware('nova.2fa.step-up:danger');

use Illuminate\Support\Facades\Gate;

Gate::define('nova-two-factor:admin', fn ($user) => $user->isAdmin());

'nova' => [
    'compliance' => ['models' => [App\Models\Admin::class]],
],

NovaTwoFactor::make()
    ->audit(Admin::class)
    ->audit(User::class, fn ($query) => $query->where('active', true));

'nova' => ['menu' => ['show' => false]],

use Gabrielesbaiz\NovaTwoFactor\NovaTwoFactor;

Nova::mainMenu(fn ($request) => [
    MenuSection::dashboard(Main::class)->icon('chart-bar'),

    MenuGroup::make(__('Two-factor'), NovaTwoFactor::menuItems()),
    MenuItem::resource(User::class),

    NovaTwoFactor::menuSection(),   // or the whole group as a top-level entry
]);

use Gabrielesbaiz\NovaTwoFactor\Nova\Actions\ResetTwoFactorAuthentication;
use Gabrielesbaiz\NovaTwoFactor\Nova\Actions\RevokeTrustedDevices;
use Gabrielesbaiz\NovaTwoFactor\Nova\Actions\SendEnrollmentReminder;
use Gabrielesbaiz\NovaTwoFactor\Nova\Fields\TwoFactorStatus;
use Gabrielesbaiz\NovaTwoFactor\Nova\Metrics\TwoFactorAdoption;
use Gabrielesbaiz\NovaTwoFactor\Nova\Metrics\TwoFactorFailures;
use Gabrielesbaiz\NovaTwoFactor\Nova\Metrics\TwoFactorMethodMix;

public function fields(NovaRequest $request): array
{
    return [
        // Sortable via subquery, so it does not N+1 a large index.
        TwoFactorStatus::make(),
    ];
}

public function actions(NovaRequest $request): array
{
    return [
        ResetTwoFactorAuthentication::make(), // 

use Gabrielesbaiz\NovaTwoFactor\Facades\TwoFactor;

TwoFactor::extend('yubico-otp', fn ($app) => new YubicoDriver(...));

'alerts' => ['lockout_burst' => ['accounts' => 5, 'window_minutes' => 15]],

'methods' => ['totp' => ['window' => 2]],

Schedule::command('nova-two-factor:prune')->daily();
bash
composer vendor:publish --tag=nova-two-factor-migrations
php artisan migrate
php artisan vendor:publish --tag=nova-two-factor-config
php artisan vendor:publish --tag=nova-two-factor-assets
bash
php artisan nova-two-factor:doctor
bash
php artisan nova-two-factor:reset [email protected]
bash
php artisan vendor:publish --tag=nova-two-factor-assets --force
php artisan vendor:publish --tag=nova-assets --force