https://github.com/bayareawebpro/laravel-simple-jwt
A simple JWT implementation for Laravel
https://github.com/bayareawebpro/laravel-simple-jwt
auth jwt laravel simple
Last synced: 6 months ago
JSON representation
A simple JWT implementation for Laravel
- Host: GitHub
- URL: https://github.com/bayareawebpro/laravel-simple-jwt
- Owner: bayareawebpro
- License: mit
- Archived: true
- Created: 2020-07-11T08:32:19.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2021-01-23T01:16:18.000Z (over 5 years ago)
- Last Synced: 2025-11-27T14:40:40.613Z (7 months ago)
- Topics: auth, jwt, laravel, simple
- Language: PHP
- Homepage: https://packagist.org/packages/bayareawebpro/laravel-simple-jwt
- Size: 31.3 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Laravel Simple JWT Authentication





```bash
composer require bayareawebpro/laravel-simple-jwt
```
### Create Encryption Secret
```shell script
artisan jwt:secret
```
### Add Secret to Environment File
```php
JWT_SECRET=XXX
```
### Configure Auth.php
```
'guards' => [
...
'api' => [
'driver' => 'simple-jwt',
'provider' => 'users',
'hash' => false,
],
],
```
### Register in Auth Service Provider.
```php
JsonWebToken::register(User::class, 'token');
```
### Create New Token, Expiration, and Claims
```php
$token = JsonWebToken::createForUser(User::first(), now()->addHours(3), [
'my_key' => true
]);
```
### Authenticate
Query String
```text
http://laravel.test/api/user?token=xxx
```
Or Header
```text
Authorization: Bearer XXX
```
### Get Claims From Token
```php
$request->jwt()->get('my_key');
$request->jwt('my_key');
```
### Extend Token Lifetime & Claims
```php
$newToken = JsonWebToken::extendToken(request()->jwt(), now()->addHours(3), ['key' => true]);
```
### Blacklist Handler
```php
$bannedUUID = request()->jwt('jti');
```
```php
JsonWebToken::rejectionHandler(fn($parsed)=>in_array($parsed->get('jti'),[
$bannedUUID
]));
```
### Testing
``` bash
composer test
composer lint
```