leonis / apikey-auth
Laravel api key auth guard.
0.3
2019-06-20 09:25 UTC
Requires
- illuminate/support: ~5.1
This package is auto-updated.
Last update: 2024-11-20 22:01:41 UTC
README
API key Authentication for Laravel and Lumen.
安装
composer require leonis/apikey-auth
配置
Laravel
-
在
config/app.php
注册 ServiceProvider (Laravel 5.5 及以上无需手动注册)'providers' => [ // ... Leonis\ApiKeyAuth\Providers\ServiceProvider::class ],
-
创建配置文件:
php artisan vendor:publish --provider="Leonis\ApiKeyAuth\ApiKeyAuthServiceProvider"
-
运行数据库迁移
php artisan migrate
lumen
-
在
bootstrap/app.php
注册 ServiceProvider$app->register(Leonis\ApiKeyAuth\Providers\ServiceProvider::class);
-
复制配置和数据库迁移文件
将
vendor/leonis/apikey-auth/config/config.php
拷贝到config
目录下,并将文件名改成api_key.php
; 将vendor/leonis/apikey-auth/database/migrations
目录中的文件拷贝到database/migrations
目录下。 -
运行数据库迁移
php artisan migrate
使用
-
修改
auth.php
配置文件中的guards
:'guards' => [ // ... 'api' => [ 'driver' => 'api_key', 'provider' => 'users', ], ],
-
为用户生成 Api Key :
ApiKey::fromUser(User::first()); ApiKey::fromId($user->id);
-
请求 API :
TODO