Skip to content
/ apikey-auth Public

API key Authentication for Laravel and Lumen.

License

Notifications You must be signed in to change notification settings

yl/apikey-auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

apikey-auth

API key Authentication for Laravel and Lumen.

安装

composer require leonis/apikey-auth

配置

Laravel

  1. config/app.php 注册 ServiceProvider (Laravel 5.5 及以上无需手动注册)

    'providers' => [
        // ...
        Leonis\ApiKeyAuth\Providers\ServiceProvider::class
     ],
  2. 创建配置文件:

    php artisan vendor:publish --provider="Leonis\ApiKeyAuth\ApiKeyAuthServiceProvider"
  3. 运行数据库迁移

    php artisan migrate

lumen

  1. bootstrap/app.php 注册 ServiceProvider

    $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. 运行数据库迁移

    php artisan migrate

使用

  1. 修改 auth.php 配置文件中的 guards :

    'guards' => [
            // ...
    
            'api' => [
                'driver' => 'api_key',
                'provider' => 'users',
            ],
        ],
  2. 为用户生成 Api Key :

    ApiKey::fromUser(User::first());
    ApiKey::fromId($user->id);
  3. 请求 API :

    TODO

License

MIT

About

API key Authentication for Laravel and Lumen.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages