pascalbaljetmedia/laravel-jwt

This package is abandoned and no longer maintained. No replacement package was suggested.

JWT for Laravel

1.1.0 2016-04-08 14:13 UTC

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

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

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.