pascalbaljetmedia / laravel-jwt
JWT for Laravel
Requires
- php: ~5.6|~7.0
- lcobucci/jwt: ^3.0|^3.1
Requires (Dev)
- orchestra/testbench: ^3.2
This package is not auto-updated.
Last update: 2020-01-28 20:25:33 UTC
README
Important: This package is not actively maintained. Please switch to Laravel Passport, a first-party package with support for JWT.
pascalbaljetmedia/laravel-jwt
Simple JWT service for Laravel
Install
Via Composer
$ composer require pascalbaljetmedia/laravel-jwt
Usage
Add the Laravel Service Provider and Facade to your app.php
config file:
return [ 'providers' => [ Pbmedia\Jwt\JwtServiceProvider::class, ], 'aliases' => [ 'Jwt' => Pbmedia\Jwt\JwtFacade::class, ] ];
Then publish the config file and update it to your needs:
$ php artisan vendor:publish --provider=Pbmedia\Jwt\JwtServiceProvider
Make sure your User Model implements AuthenticatableInterface
:
use Pbmedia\Jwt\AuthenticatableInterface; class User extends Model implements AuthenticatableInterface { public function findByQualifiedKeyForToken($id) { return static::find($id); } public function getQualifiedKeyForToken() { return $this->getKey(); } }
Now you can use TokenService
to generate tokens, find users and validate tokens:
use \Jwt; $user = User::first(); $token = (string) Jwt::generateTokenForUser($user); $user = Jwt::findUserByTokenOrFail($token); $validToken = Jwt::tokenIsValid($token);
Change log
Please see CHANGELOG for more information what has changed recently.
Testing
$ composer test
Contributing
Please see CONTRIBUTING and CONDUCT for details.
Security
If you discover any security related issues, please email pascal@pascalbaljetmedia.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.