tech-djoin/laravel-admin-ext-google-authenticator
最新稳定版本:v1.0.1
Composer 安装命令:
composer require tech-djoin/laravel-admin-ext-google-authenticator
包简介
Google Authenticator extension for laravel-admin
README 文档
README
Two-Factor Authentication (2FA) extension for Laravel Admin using Google Authenticator.
Features
- Enable/Disable 2FA for individual admin users
- QR code scanning for easy setup
- Verification page for 2FA codes
- Configurable settings via .env file
- Middleware protection for admin routes
Installation
-
Install the package via Composer:
composer require tech-djoin/laravel-admin-ext-google-authenticator
-
Publish assets and configuration:
php artisan vendor:publish --provider="TechDjoin\LaravelAdminGoogleAuthenticator\GoogleAuthenticatorServiceProvider" --tag="config"
-
Customize the configuration file in
config/google2fa.phpas needed. -
Run migrations:
php artisan migrate
-
Override the
Administrator.phpfile in the/vendor/encore/laravel-admin/src/Auth/Databasedirectory and update your admin user model (usually inApp/Models/AdminUser.php):<?php namespace App\Models; use Encore\Admin\Auth\Database\Administrator; use Illuminate\Notifications\Notifiable; use TechDjoin\LaravelAdminGoogleAuthenticator\Traits\Google2FAAuthenticatableTrait; class AdminUser extends Administrator { use Notifiable; use Google2FAAuthenticatableTrait; protected $fillable = ['username', 'password', 'name', 'avatar', 'google2fa_secret']; public function setGoogle2faSecretAttribute($value) { $this->attributes['google2fa_secret'] = !is_null($value) ? encrypt($value) : null; } public function getGoogle2faSecretAttribute($value) { return isset($value) ? decrypt($value) : null; } }
-
Update
config/admin.php:'auth' => [ 'model' => App\Models\AdminUser::class, ], 'database' => [ 'users_model' => App\Models\AdminUser::class ],
-
Install PHP Imagick extension for QR code generation.
Configuration (Optional)
You can configure the extension by editing config/google2fa.php or setting values in your .env file:
ADMIN_2FA_ENABLED=true
ADMIN_2FA_LIFETIME=0
ADMIN_2FA_KEEP_ALIVE=true
Installing Imagick PHP Extension
Windows
- Download and extract files from PECL Imagick Extension.
- Copy
php_imagick.dllto the PHPextfolder. - Copy all
.dllfiles from thebinfolder to the main PHP folder. - Edit
php.ini, add the lineextension=imagick. - Restart the web server.
Linux (Ubuntu/Debian)
-
Update repository:
sudo apt update
-
Install Imagick:
- PHP 7.x:
sudo apt install php-imagick - PHP 8.x:
sudo apt install php8.x-imagick
- PHP 7.x:
-
Restart web server:
- Apache:
sudo systemctl restart apache2 - Nginx:
sudo systemctl restart nginx
- Apache:
Verify the installation by running php -m | grep imagick.
统计信息
- 总下载量: 14
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-10-16