https://github.com/yl/apikey-auth
API key Authentication for Laravel and Lumen.
https://github.com/yl/apikey-auth
Last synced: 5 months ago
JSON representation
API key Authentication for Laravel and Lumen.
- Host: GitHub
- URL: https://github.com/yl/apikey-auth
- Owner: yl
- License: mit
- Created: 2018-11-06T07:40:57.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-06-20T09:25:54.000Z (about 7 years ago)
- Last Synced: 2025-10-03T07:42:28.213Z (9 months ago)
- Language: PHP
- Size: 11.7 KB
- Stars: 1
- Watchers: 0
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# apikey-auth
API key Authentication for Laravel and Lumen.
## 安装
```bash
composer require leonis/apikey-auth
```
## 配置
### Laravel
1. 在 `config/app.php` 注册 ServiceProvider (Laravel 5.5 及以上无需手动注册)
```php
'providers' => [
// ...
Leonis\ApiKeyAuth\Providers\ServiceProvider::class
],
```
2. 创建配置文件:
```bash
php artisan vendor:publish --provider="Leonis\ApiKeyAuth\ApiKeyAuthServiceProvider"
```
3. 运行数据库迁移
```bash
php artisan migrate
```
### lumen
1. 在 `bootstrap/app.php` 注册 ServiceProvider
```php
$app->register(Leonis\ApiKeyAuth\Providers\ServiceProvider::class);
```
2. 复制配置和数据库迁移文件
将 `vendor/leonis/apikey-auth/config/config.php` 拷贝到 `config` 目录下,并将文件名改成 `api_key.php`;
将 `vendor/leonis/apikey-auth/database/migrations` 目录中的文件拷贝到 `database/migrations` 目录下。
3. 运行数据库迁移
```bash
php artisan migrate
```
## 使用
1. 修改 `auth.php` 配置文件中的 `guards` :
```php
'guards' => [
// ...
'api' => [
'driver' => 'api_key',
'provider' => 'users',
],
],
```
2. 为用户生成 Api Key :
```php
ApiKey::fromUser(User::first());
ApiKey::fromId($user->id);
```
3. 请求 API :
TODO
## License
[MIT](https://opensource.org/licenses/MIT)