antarccub / jwt-auth
JWT Authentication for Laravel projects
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: 2025-02-18 18:11:06 UTC
README
JWT-Auth for Laravel
Installation
Package is available on Packagist,
you can install it using Composer.
composer require antarccub/jwt-auth
After that, you need to publish config file with the following command:
php artisan vendor:publish --tag:jwt-config
To start using the package you have to change your auth driver in the auth.php file:
'guards' => [
'web' => [ 'driver' => 'session', 'provider' => 'users', ],
'api' => [ 'driver' => 'jwt', // JWT Auth 'provider' => 'users', ], ],
Basic Usage
Now you can use Laravel Auth facade with JWT Authentication
Route::middleware('auth:api')->get('/user', function (Request $request) {
return response()->json(Auth::user());
});
Configuration
/*
* 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' ] ]
Contributing
This package is for my personal use, but feel free to change all you want!