wnx/laravel-tfa-confirmation
Composer 安装命令:
composer require wnx/laravel-tfa-confirmation
包简介
Protect sensitive routes or actions with a confirmation-screen and ask for the two-factor authentication code of a user
README 文档
README
Protect sensitive routes or actions with a confirmation-screen and ask for the two-factor authentication code of a user. Users are not asked for a confirmation again for a given time period. (Similar to the Password Confirmation feature of Laravel.)
The package uses Laravel Fortify under the hood to confirm the two-factor authentication code.
Installation
You can install the package via composer:
composer require wnx/laravel-tfa-confirmation
You can publish the config file with:
php artisan vendor:publish --tag="tfa-confirmation-config"
This is the contents of the published config file:
<?php use Wnx\TfaConfirmation\Http\Controllers\ConfirmTwoFactorAuthenticationCodeController; use Wnx\TfaConfirmation\Http\Controllers\TwoFactorAuthenticationChallengeController; use Wnx\TfaConfirmation\Http\Responses\DefaultJsonResponse; return [ /** * Enable or disable two-factor authentication confirmation. */ 'enabled' => env('TFA_CONFIRMATION_ENABLED', true), /** * The session key that is used to store the timestamp of the last time * the user confirmed their two-factor authentication code. */ 'session_key' => 'auth.two_factor_confirmed_at', /** * The amount of time in seconds the confirmation is valid. * Users will not be asked to enter their two-factor authentication code again for this amount of time. */ 'timeout' => env('TFA_CONFIRMATION_TIMEOUT', 60 * 60 * 24), // 24 hours /** * The view that should be returned when the user needs to confirm their two-factor authentication code. * You should publish the views to your application to customize the challenge view. */ 'challenge_view' => 'tfa-confirmation::challenge', /** * Controller used to show the two-factor authentication challenge view. */ 'challenge_controller' => TwoFactorAuthenticationChallengeController::class, /** * Controller used to confirm the two-factor authentication code entered by the user on the challenge view. * If you customize this controller, make sure to dispatch the `\Laravel\Fortify\Events\ValidTwoFactorAuthenticationCodeProvided` event. */ 'confirmation_controller' => ConfirmTwoFactorAuthenticationCodeController::class, /** * The response that should be returned when the user needs to confirm their * two-factor authentication code, but the request expects a JSON response. */ 'json_response' => DefaultJsonResponse::class, ];
The defaul challenge-view is not styled. We highly recommend you publish the views and customize them to your design.
php artisan vendor:publish --tag="tfa-confirmation-views"
Usage
To protect routes with a two-factor confirmation challenge add the \Wnx\TfaConfirmation\Http\Middleware\RequireTwoFactorAuthenticationConfirmation-middleware to your routes.
// routes/web.php // Protect a single route Route::get('/super-important-route', SuperImportantController::class) ->middleware([ // Use Middleware directly \Wnx\TfaConfirmation\Http\Middleware\RequireTwoFactorAuthenticationConfirmation::class, // Use Middleware alias 'require_twofactor_confirmation', ]); // Protect a group of routes Route::middleware([ 'auth:sanctum', 'verified', \Wnx\TfaConfirmation\Http\Middleware\RequireTwoFactorAuthenticationConfirmation::class, ])->group(function () { // Routes that need to be protected by two factor authentication });
Note
If a given user does not have two-factor authentication enabled, the middleware is bypassed and the user will not be asked to confirm their two-factor authentication code. If you want certain routes only to be available to users with two-factor authentication enabled, you have to write a custom middleware that checks this condition.
Note
The package listens to the Laravel\Fortify\Events\ValidTwoFactorAuthenticationCodeProvided event to store the timestamp of the last time the user confirmed their two-factor authentication code. This ensures that the user is not asked to confirm their two-factor authentication code right after logging in.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
wnx/laravel-tfa-confirmation 适用场景与选型建议
wnx/laravel-tfa-confirmation 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.14k 次下载、GitHub Stars 达 31, 最近一次更新时间为 2024 年 12 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「two-factor-authentication」 「fortify」 「Stefan Zweifel」 「laravel-tfa-confirmation」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 wnx/laravel-tfa-confirmation 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 wnx/laravel-tfa-confirmation 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 wnx/laravel-tfa-confirmation 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This package provides Laravel bindings and a Eloquent/Model trait for pragmarx/recovery package.
Front-end scafolding for laravel/fortify based on bootstrap
Enable Google 2FA (two factor authentication) for both, frontend- and backend accounts.
Free and open source ecommerce platform, created in 2024 on the M1 platform, PHP 8.3+
UIkit starter template for Laravel
2FA integration for Laravel Backpack using Fortify
统计信息
- 总下载量: 1.14k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 31
- 点击次数: 38
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-12-21