antarccub / jwt-auth
Laravel项目的JWT身份验证
1.0.2
2018-04-17 21:59 UTC
Requires
- php: >=5.6.4
- guzzlehttp/guzzle: ^6.3
- illuminate/auth: ^5.4
- illuminate/contracts: >=5.0
- illuminate/support: >=5.0
- lcobucci/jwt: 3.2.*
Requires (Dev)
- mockery/mockery: 0.9.*
- phpunit/phpunit: ~5.7
This package is auto-updated.
Last update: 2024-09-18 17:22:31 UTC
README
Laravel的JWT-Auth
安装
该包可在Packagist上找到,
您可以使用Composer进行安装。
composer require antarccub/jwt-auth
之后,您需要使用以下命令发布配置文件
php artisan vendor:publish --tag:jwt-config
要开始使用此包,您必须在auth.php文件中更改您的身份验证驱动程序
'guards' => [
'web' => [ 'driver' => 'session', 'provider' => 'users', ],
'api' => [ 'driver' => 'jwt', // JWT Auth 'provider' => 'users', ], ],
基本用法
现在您可以使用Laravel Auth门面与JWT身份验证一起使用
Route::middleware('auth:api')->get('/user', function (Request $request) {
return response()->json(Auth::user());
});
配置
/*
* Here you can add all claims (iss, aud, jti, sub) you want to validate and theirs corresponding value * * Example: * 'iss' => 'http://example.com', * * 'jti' => '123123j2j3oj' * */
'claims' => [
// 'iss' => 'http://example.com',
],
/* * Here you can config the signature verification type * */
'signature' => 'public-key', // public-key | secret
'methods' => [ 'public-key' => [ 'type' => 'RSA', // RSA, ECDSA 'signer' => 'SHA256', // RSA256, RSA348, RSA512 'provider' => 'Antarccub\JwtAuth\Providers\PublicKeyFileProvider',
'content' => storage_path('public.key'), // Only for PublicKeyFileProvider 'url' => env('JWT_PKEY') // Only for PublicKeyUrlProvider ],
'secret' => [ 'signer' => 'SHA256', 'value' => 'example' ] ]
贡献
此包仅供个人使用,但您可以随意更改!