定制 wnx/laravel-tfa-confirmation 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 wnx/laravel-tfa-confirmation 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.14k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 31
  • 点击次数: 38
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 31
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-12-21