PHPackages                             aikrof/jwt-auth - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. aikrof/jwt-auth

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

aikrof/jwt-auth
===============

Simple JSON Web Token Authentication for Laravel

1.0.0(6y ago)09MITPHPPHP &gt;=7.1.8

Since Nov 11Pushed 5y ago1 watchersCompare

[ Source](https://github.com/Aikrof/jwt-auth)[ Packagist](https://packagist.org/packages/aikrof/jwt-auth)[ Docs](https://github.com/Aikrof/jwt-auth)[ RSS](/packages/aikrof-jwt-auth/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (7)Versions (2)Used By (0)

Simple JSON Web Token Authentication
====================================

[](#simple-json-web-token-authentication)

#### 1. Instalation

[](#1-instalation)

```
composer require aikrof/jwt-auth
```

---

#### 2. Add service provider

[](#2-add-service-provider)

Add the service provider to the `providers` array in the `config/app.php` config file:

```
'providers' => [
    ...
    Aikrof\JwtAuth\Providers\JwtServiceProvider::class,
    ...
],
```

---

#### 3. Publish the config file

[](#3-publish-the-config-file)

```
php artisan vendor:publish --provider="Aikrof\JwtAuth\Providers\JwtServiceProvider"
```

This command will be create `config/jwt.php` file with basics configure.

---

#### 4. Migrate table

[](#4-migrate-table)

Create table where will be stored invalid tokens.

```
php artisan migrate
```

---

#### 5. Generate secret and refresh keys

[](#5-generate-secret-and-refresh-keys)

```
php artisan create:secret
```

This command will create JWT\_SECRET\_KEY and JWT\_REFRESH\_KEY in your `.env` file.

---

#### 6. Configure Auth guard

[](#6-configure-auth-guard)

Inside the `config/auth.php` file change:

```
    'defaults' => [
        'guard' => 'api',
        'passwords' => 'users',
    ],
    ...
    'guards' => [
        ...
        'api' => [
            'driver' => 'jwt',
            'provider' => 'users',
        ],
    ],
```

Set `api` guard as the default and add `jwt` driver to `api` guard

---

#### 7. Update your User model

[](#7-update-your-user-model)

Add `trait` to your User model:
1)Implement the `Aikrof\JwtAuth\JwtCreator`
2)Then add trait `use JwtCreator`

```
namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Aikrof\JwtAuth\JwtCreator;

class User extends Authenticatable
{
    use JwtCreator, Notifiable;

    ....
}
```

---

#### 8. Usage

[](#8-usage)

##### 1)Set tokens time to live

[](#1set-tokens-time-to-live)

##### 1. Set token time to live

[](#1-set-token-time-to-live)

By default token time to live (`ttl`) is 1 week, you can change `ttl` in `config/jwt.php` file or when create new token:

```
Auth::user()->setTtl(2);
```

Example sets token time to live by 2 minutes.
`setTtl()` -takes parameter in minutes.

##### 1. Set refresh token time to live

[](#1-set-refresh-token-time-to-live)

By default refresh token time to live is `token ttl * 2`, you can change `refreshTtl` in `config/jwt.php` file or when create new token:

```
Auth::user()->setRefreshTtl(4);
```

Example sets token time to live by 4 minutes.
`setRefreshTtl()` -takes parameter in minutes.

---

##### 2)Create JWT token and refresh token

[](#2create-jwt-token-and-refresh-token)

```
Auth::token();
```

Or with `setTtl() or setRefreshTtl()`

```
Auth::user()->setTtl(2)->setRefreshTtl()->token();
```

Will be returned array with this fields:

```
[
    'token' => '...',
    'refresh' => '...'
]
```

---

##### 3)Get tokens time to live

[](#3get-tokens-time-to-live)

##### 1. To get token time to live in minutes

[](#1-to-get-token-time-to-live-in-minutes)

```
Auth::user()->getTtl();
```

To get token time to live in UNIX timestamp

```
Auth::user()->getExpTtl();
```

##### 2. To get refresh token time to live in minutes

[](#2-to-get-refresh-token-time-to-live-in-minutes)

```
Auth::user()->getRefreshTtl();
```

To get refresh token time to live in UNIX timestamp

```
Auth::user()->getRefreshExpTtl();
```

---

##### 4)Logout user

[](#4logout-user)

Log the user out - which will invalidate the current token and unset the authenticated user.

```
Auth::logout();
```

---

##### 5)Refresh JWT tokens

[](#5refresh-jwt-tokens)

Refresh a token, which invalidates the current one and returned new token and refresh token.

```
Auth::refresh();
```

If jwt token was invalid or have invalid data then will be returned `null`.

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2423d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/53342059?v=4)[Denys Minakov](/maintainers/Aikrof)[@Aikrof](https://github.com/Aikrof)

---

Top Contributors

[![Aikrof](https://avatars.githubusercontent.com/u/53342059?v=4)](https://github.com/Aikrof "Aikrof (2 commits)")

---

Tags

jwtauthAuthenticationJSON Web Token

### Embed Badge

![Health badge](/badges/aikrof-jwt-auth/health.svg)

```
[![Health](https://phpackages.com/badges/aikrof-jwt-auth/health.svg)](https://phpackages.com/packages/aikrof-jwt-auth)
```

###  Alternatives

[tymon/jwt-auth

JSON Web Token Authentication for Laravel and Lumen

11.5k50.9M364](/packages/tymon-jwt-auth)[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k51.0M7.7k](/packages/larastan-larastan)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k14.1M123](/packages/laravel-pulse)[php-open-source-saver/jwt-auth

JSON Web Token Authentication for Laravel and Lumen

83910.6M60](/packages/php-open-source-saver-jwt-auth)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
