mathewberry/tokenizer

该包已废弃,不再维护。未建议替代包。

适用于微服务的一个非常轻量级的标记系统

0.2.4 2017-08-09 13:16 UTC

This package is auto-updated.

Last update: 2020-10-21 14:53:56 UTC


README

适用于微服务的一个非常轻量级的标记系统

Lumen 安装

服务提供者

移除

$app->register(App\Providers\AuthServiceProvider::class); 

添加

$app->register(Mathewberry\Tokenizer\TokenizerServiceProvider::class); 

路由中间件

移除

'auth' => App\Http\Middleware\Authenticate::class, 

添加

'auth' => Mathewberry\Tokenizer\Middleware\Authenticate::class, 

生成新令牌

php artisan token:generate

实现令牌

将生成的令牌复制到你的 .env 文件中的一个新键,称为 API_TOKEN

使用方法

每次调用时,只需传递头部 api_token,其值为你的 .env 中的令牌值。

请确保你的路由或控制器正在使用 auth 中间件。

示例

class DomainController extends Controller
{
    public function __construct()
    {
        $this->middleware(['auth']);
    }
    
    public function index()
    {
        $domains = Domain::get();
        
        return response($domains, 200);
    }
}

就这么简单,你的微服务现在更加安全了。