stia/authid-php
最新稳定版本:1.0.2
Composer 安装命令:
composer require stia/authid-php
包简介
SDK / Plugin to handle Authenticator for Auth ID
README 文档
README
- Laravel 10 or later
- PHP 8.1 or later
Instalation Guide
Install dependency with composer
composer require stia/authid-php
Publish the config file
php artisan vendor:publish --provider="Stia\AuthidPhp\AuthIDServiceProvider"
Run the migration
php artisan migrate
To enable 2 FA, add the following code to the User model
use TwoFactorAuthenticatable;
Example:
class User extends Authenticatable { use HasApiTokens, HasFactory, Notifiable; use TwoFactorAuthenticatable; /** * The attributes that are mass assignable. * * @var array<int, string> */ protected $fillable = [ ...
Method Usage
Check is user already have recovery codes
$user = User::find($id); $isEnabled = $user->hasEnabledTwoFactorAuthentication(); return $isEnabled;
Generate new recovery codes
$user = User::find($id); $user->generateNewRecoveryCode();
Get user recovery codes
$user = User::find($id); $recoveryCodes = $user->recoveryCodes(); return $recoveryCodes;
Enable 2FA and generate QR code
namespace App\Http\Controllers; use Stia\AuthidPhp\Actions\EnableTwoFactorAuthentication; class UserController extends Controller { public function enableTwoFactorAuthentication(EnableTwoFactorAuthentication $enableAction) { $user = auth()->user(); $enableAction($user); return $user->twoFactorQrCodeSvg(); } }
Validate 2FA
namespace App\Http\Controllers; use Illuminate\Support\Facades\Request; use Stia\AuthidPhp\Actions\EnableTwoFactorAuthentication; use Stia\AuthidPhp\Actions\IsTwoFactorAuthenticationValid; class UserController extends Controller { public function validateTwoFactorAuthentication(Request $request, IsTwoFactorAuthenticationValid $confirm) { if ($confirm($request->user(), $request->code)) { return 'OK'; } return 'Code not valid'; } ...
统计信息
- 总下载量: 14
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2025-02-19