juliomotol/laravel-auth-timeout
Composer 安装命令:
composer require juliomotol/laravel-auth-timeout
包简介
Authentication Timeout for Laravel
README 文档
README
Handle Authentication timeouts in Laravel.
When upgrading to v4, please see the CHANGELOG.md.
For Laravel 8+ support, see v3.
For Laravel 6+ support, see v2.
Why Laravel Auth Timeout?
There are times where we want to log out a user when they haven't done any request within a set time. There is a workaround (below):
/* Somewhere in config/session.php */
'lifetime' => 15,
But this affects the entirety of the session. But it doesnt have to be and that is where Laravel Auth Timeout comes in.
Laravel Auth Timeout is a small middleware package that checks if the user had made any request in a set of time. If they have reached the idle time limit, they are then logged out on their next request. Thanks to Brian Matovu's article.
Installation
You can install the package via composer:
composer require juliomotol/laravel-auth-timeout
You can publish the config file with:
php artisan vendor:publish --tag="auth-timeout-config"
This is the contents of the published config file:
<?php return [ /** * The session name used to identify if the user has reached the timeout time. */ 'session' => 'last_activity_time', /** * The minutes of idle time before the user is logged out. */ 'timeout' => 15, /** * The event that will be dispatched when a user has timed out. */ 'event' => JulioMotol\AuthTimeout\Events\AuthTimedOut::class, ];
Usage
Quick Start
For a simple usage, register the CheckAuthTimeout in your Kernel.php.
protected $routeMiddleware = [ ... 'auth.timeout' => \JulioMotol\AuthTimeout\Middlewares\CheckAuthTimeout::class, ... ];
Then use that middleware on a route.
Route::get('/admin', [ 'uses' => 'FooBarController@Foobar', 'middleware' => ['auth.timeout'] ]);
Using Different Guards
You might have multiple guards and only want to apply CheckAuthTimeout to certain ones. We got you covered, CheckAuthTimeout accepts a $guard parameter.
Route::get('/admin', [ 'uses' => 'FooBarController@Foobar', 'middleware' => ['auth.timeout:custom-guard'] // Add the guard name as a parameter for the auth.timeout middleware. ]);
NOTE: This package only works with guards that uses a
sessiondriver.
AuthTimedOut
An AuthTimedOut will be dispatch every time a user has timed out. You can assign a listener for this event in your EventServiceProvider.
protected $listen = [ \JulioMotol\AuthTimeout\Events\AuthTimedOut::class => [ // ... ], ];
AuthTimedOut has two properties that you can access in your EventListener.
class FooEventListener { public function handle(AuthTimedOut $event) { $event->user; $event->guard; } }
Redirection
To modify the redirection when a user has timed out, you can use CheckAuthTimeout::setRedirectTo() within your AppServiceProvider to set a redirection callback.
class AppServiceProvider extends ServiceProvider { public function boot() { CheckAuthTimeout::setRedirectTo(function ($request, $guard){ return match($guard){ 'custom-guard' => route('some.route'), default => route('auth.login') }; }); } }
AuthTimeout Facade
This package also provides a facade with the following methods:
AuthTimeout::init() // Initialize the timeout session when no has been set yet. AuthTimeout::check($guard) // Check if a user has timed out and logs them out if so. AuthTimeout::hit() // Reset the user's timeout session. AuthTimeout::lastActiveAt() // The last activity time of the user.
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.
juliomotol/laravel-auth-timeout 适用场景与选型建议
juliomotol/laravel-auth-timeout 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 141.63k 次下载、GitHub Stars 达 43, 最近一次更新时间为 2020 年 04 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Authentication」 「auth」 「laravel」 「timeout」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 juliomotol/laravel-auth-timeout 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 juliomotol/laravel-auth-timeout 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 juliomotol/laravel-auth-timeout 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Laravel Multiauth package
Automatically logs-in users if they are already authenticated by a remote source. (e.g. environment variable REMOTE_USER)
GraphQL authentication for your headless Craft CMS applications.
A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.
Laravel middleware to restrict a site or specific routes using HTTP basic authentication
This package provides a flexible way to add Role-based Permissions to Laravel 6.x
统计信息
- 总下载量: 141.63k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 43
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-04-03