imunew/tymon-jwt-auth
最新稳定版本:0.4
Composer 安装命令:
composer require imunew/tymon-jwt-auth
包简介
README 文档
README
This is the Laravel package to extend tymon/jwt-auth.
Extended what?
- Disable the
QueryString,InputSourceandRouteParamsparsers - Made the
AuthHeadersparser optional (Default: disabled) - Prefer the
Cookiesparser - Made the cookie name changeable
- Add
AuthResource(with cookie) - Add
RefreshJwtTokenmiddleware (with cookie)
Install
$ composer require imunew/tymon-jwt-auth
vendor:publish
$ php artisan vendor:publish --provider="Imunew\JWTAuth\Providers\ServiceProvider"
Config
Set JWT_AUTH_COOKIE_KEY environment variable to change the cookie name.
JWT_AUTH_COOKIE_KEY={cookie name here}
Set JWT_AUTH_AUTH_HEADER_ENABLED environment variable to enable the AuthHeaders parser.
JWT_AUTH_AUTH_HEADER_ENABLED=true
Use AuthResource
Returning AuthResource sets JWT token in cookie.
// App\Http\Controllers\Auth\Login public function __invoke(LoginRequest $request) { $credentials = $request->only(['login_id', 'password']); if (! $token = $this->jwtGuard->attempt($credentials)) { throw new AuthenticationException(); } return new AuthResource(new JwtToken($token, $this->factory->getTTL() * 60)); }
Use RefreshJwtToken
Add \Imunew\JWTAuth\Middleware\RefreshJwtToken::class before \App\Http\Middleware\Authenticate::class.
// App\Http\Kernel protected $middlewarePriority = [ \Illuminate\Session\Middleware\StartSession::class, \Illuminate\View\Middleware\ShareErrorsFromSession::class, \Imunew\JWTAuth\Middleware\RefreshJwtToken::class, \App\Http\Middleware\Authenticate::class, \Illuminate\Routing\Middleware\ThrottleRequests::class, \Illuminate\Session\Middleware\AuthenticateSession::class, \Illuminate\Routing\Middleware\SubstituteBindings::class, \Illuminate\Auth\Middleware\Authorize::class, ];
Add \Imunew\JWTAuth\Middleware\RefreshJwtToken::class to $middlewareGroups.
// App\Http\Kernel protected $middlewareGroups = [ 'web' => [ // ... ], 'api' => [ 'throttle:60,1', \Illuminate\Routing\Middleware\SubstituteBindings::class, \Imunew\JWTAuth\Middleware\RefreshJwtToken::class, ] ];
统计信息
- 总下载量: 11.84k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-04-26