This package enables 2FA on Laravel Nova.
- User gets recovery codes.
- User activates 2FA on his device.
- User verifies login with 2FA.
- If user enters an invalid code, recovery button is shown.
- User enters a recovery code.
- User is redirected to activation process.
Installation is only available via composer
"repositories": [
{
"type": "vcs",
"url": "https://github.com/383Project/nova-google2fa"
}
]
"require": {
"383project/nova-google2fa": "dev-master"
}
Publish config and migrations
$ php artisan vendor:publish --provider="Project383\Google2fa\ToolServiceProvider"
$ php artisan vendor:publish --provider="PragmaRX\Google2FALaravel\ServiceProvider"
Run migrations
$ php artisan migrate
Add relation to User model
use Project383\Google2fa\Models\User2fa;
...
/**
* @return HasOne
*/
public function user2fa(): HasOne
{
return $this->hasOne(User2fa::class);
}
Add enabled_2fa
field to User model database table
$table->boolean('enabled_2fa')->nullable()->default(false);
Add middleware to config/nova.php
.
[
...
'middleware' => [
...
\Project383\Google2fa\Http\Middleware\Google2fa::class,
...
],
]
return [
/**
* Disable or enable middleware.
*/
'enabled' => env('GOOGLE_2FA_ENABLED', true),
'models' => [
/**
* Change this variable to path to user model.
*/
'user' => 'App\User',
/**
* Change this if you need a custom connector
*/
'user2fa' => User2fa::class,
],
'tables' => [
/**
* Table in which users are stored.
*/
'user' => 'users',
],
'recovery_codes' => [
/**
* Number of recovery codes that will be generated.
*/
'count' => 8,
/**
* Number of blocks in each recovery code.
*/
'blocks' => 3,
/**
* Number of characters in each block in recovery code.
*/
'chars_in_block' => 16,
/**
* The following algorithms are currently supported:
* - PASSWORD_DEFAULT
* - PASSWORD_BCRYPT
* - PASSWORD_ARGON2I // available from php 7.2
*/
'hashing_algorithm' => PASSWORD_BCRYPT,
],
];
MIT license. Please see the license file for more information.