<?php namespace App\Http; use Illuminate\Foundation\Http\Kernel as HttpKernel; class Kernel extends HttpKernel { ... protected $routeMiddleware = [ 'token.refresh' => \App\Http\Middleware\RefreshToken::class, 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, 'can' => \Illuminate\Auth\Middleware\Authorize::class, 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, ]; }
相应的控制器构造函数修改:
public function __construct() { $this->middleware('token.refresh', ['except' => ['login','refresh']]); }
把token时间设置成1分钟,测试一下。
可以根据api返回,去调用刷新接口。
简单使用就是这样啦。
总结
到此这篇关于Laravel配合jwt使用的文章就介绍到这了,更多相关Laravel配合jwt使用内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
您可能感兴趣的文章: