hryha / simple-basic-auth
Laravel 基础认证
v1.2
2024-04-10 14:05 UTC
Requires
- php: >7.4
- illuminate/support: >6.0
README
此包允许您在路由上添加 HTTP 基础认证过滤器,而无需使用数据库——这是 Laravel 默认 simple-basic-auth
中间件所依赖的。
认证失败时,用户将收到 "401 未授权" 的响应。
安装
通过 Composer
$ composer require hryha/simple-basic-auth
此包使用包自动发现来加载服务提供者
如果您想手动添加提供者,请关闭 composer.json 文件中的包自动发现
"extra": {
"laravel": {
"dont-discover": [
"hryha/simple-basic-auth"
]
}
},
然后在 providers 数组中添加提供者(config/app.php
)。
'providers' => [
Hryha\SimpleBasicAuth\SimpleBasicAuthServiceProvider::class
]
配置
运行命令 $ php artisan vendor:publish --provider="Hryha\SimpleBasicAuth\SimpleBasicAuthServiceProvider"
直接发布文件。
然后,将文件 simple-basic-auth.php
复制到您的 app/config
文件夹——在这里您可以设置各种登录名和密码。
用法
中间件使用 simple-basic-auth
过滤器来保护路由。您可以使用 Route::group()
保护多个路由,也可以单独保护它们。
分组
Route::group(['middleware' => 'simple-basic-auth'], function() {
...
});
单个
Route::get('/', ['middleware' => 'simple-basic-auth']);
您还可以直接设置用户登录名;
Route::get('/', ['middleware' => 'simple-basic-auth:login1,login2']);
许可证
MIT 许可证 (MIT)。