定制 juliomotol/laravel-auth-timeout 二次开发

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

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

juliomotol/laravel-auth-timeout

Composer 安装命令:

composer require juliomotol/laravel-auth-timeout

包简介

Authentication Timeout for Laravel

README 文档

README

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

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 session driver.

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 141.63k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 43
  • 点击次数: 20
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 43
  • Watchers: 1
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-04-03