承接 arubacao/http-basic-auth-guard 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

arubacao/http-basic-auth-guard

Composer 安装命令:

composer require arubacao/http-basic-auth-guard

包简介

HTTP Basic Auth Guard for Lumen >=5.2

README 文档

README

Latest Version on Packagist Software License Total Downloads

HTTP Basic Auth Guard is a Lumen Package that lets you use basic as your driver for the authentication guard in your application.

The Guard brings back the missing stateless HTTP Basic Authentication possibilities for Lumen >=5.2.

Explanation

As of Lumen 5.2 the session storage is not included anymore.
Unfortunately, for calling Auth::onceBasic(), Auth::basic(), or alike you'll need the session driver which requires the session storage.
Therefore HTTP Basic Authentication does not work out-of-the-box anymore for Lumen >=5.2.
To be honest, I have no idea why Taylor Otwell removed this functionality from Lumen 5.2.
My best guess is, that he doesn't even know since my issue got closed instantly on github 😃
Luckily, this package brings the usual functionality back!

Requirements

  • Lumen 5.2 or above Installation.
  • Note: For Laravel 5.* or Lumen 5.1 HTTP Basic Auth still works out-of-the-box with the session driver: Link.

Tested with

  • Lumen 5.2, 5.3, 5.4, 5.5, 5.6, 5.7
  • PHP 5.6, 7.0, 7.1, 7.2, 7.3

Current master is for Lumen >= 5.7. For Lumen <= 5.6 Use version ^1.0.

Installation

1. Pull in package

$ composer require arubacao/http-basic-auth-guard

2. Read & Follow Official Lumen Documentation for Authentication

https://lumen.laravel.com/docs/5.7/authentication

Important:

Before using Lumen's authentication features, you should uncomment the call to register the AuthServiceProvider service provider in your bootstrap/app.php file.

// bootstrap/app.php

// Uncomment the following line 
 $app->register(App\Providers\AuthServiceProvider::class);

Of course, any routes you wish to authenticate should be assigned the auth middleware, so you should uncomment the call to $app->routeMiddleware() in your bootstrap/app.php file:

// bootstrap/app.php

// Uncomment the following lines
 $app->routeMiddleware([
    'auth' => App\Http\Middleware\Authenticate::class,
 ]);

If you would like to use Auth::user() to access the currently authenticated user, you should uncomment the $app->withFacades() method in your bootstrap/app.php file.

// bootstrap/app.php

// Uncomment the following lines
 $app->withFacades();
 $app->withEloquent();

3. Add the Service Provider

Open bootstrap/app.php and register the service provider:

// bootstrap/app.php

// Add the following line
$app->register(Arubacao\BasicAuth\BasicGuardServiceProvider::class);

4. Setup Guard Driver

Note: In Lumen you first have to copy the config file from the directory vendor/laravel/lumen-framework/config/auth.php, create a config folder in your root folder and finally paste the copied file there.

$ mkdir config
$ cp vendor/laravel/lumen-framework/config/auth.php config/

Open your config/auth.php config file.
In guards add a new key of your choice (api in this example).
Add basic as the driver.
Make sure you also set provider for the guard to communicate with your database.

// config/auth.php
'guards' => [
    'api' => [
        'driver' => 'basic',
        'provider' => 'users'
    ],

    // ...
],

'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model'  => App\User::class,
    ],
],

Usage

Middleware protecting the route:

Route::get('api/whatever', ['middleware' => 'auth:api', 'uses' => 'NiceController@awesome']);

Middleware protecting the controller:

<?php

namespace App\Http\Controllers;

class NiceController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth:api');
    }
}

Change log

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Any issues, feedback, suggestions or questions please use issue tracker here.

Security

If you discover any security related issues, please email arubacao@gmail.com instead of using the issue tracker.

License

The MIT License (MIT).

Analytics

arubacao/http-basic-auth-guard 适用场景与选型建议

arubacao/http-basic-auth-guard 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 55.77k 次下载、GitHub Stars 达 40, 最近一次更新时间为 2016 年 03 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「lumen」 「http basic auth」 「Lumen 5.2」 「http basic auth guard」 「http basic authentication」 「http basic auth guard lumen」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 arubacao/http-basic-auth-guard 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 arubacao/http-basic-auth-guard 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 55.77k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 41
  • 点击次数: 26
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 40
  • Watchers: 6
  • Forks: 10
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-03-20