PHPackages                             jekk0/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. jekk0/jwt-auth

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

jekk0/jwt-auth
==============

JWT Authentication for Laravel

1.0.0(1y ago)030MITPHPPHP ^8.1CI passing

Since Mar 7Pushed 1y ago1 watchersCompare

[ Source](https://github.com/jekk0/jwt-auth)[ Packagist](https://packagist.org/packages/jekk0/jwt-auth)[ Docs](https://github.com/jekk0/jwt-auth)[ RSS](/packages/jekk0-jwt-auth/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (10)Versions (7)Used By (0)

Laravel JWT Authentication
==========================

[](#laravel-jwt-authentication)

[![Build Status](https://github.com/jekk0/jwt-auth/actions/workflows/pipeline.yml/badge.svg?branch=main)](https://github.com/jekk0/jwt-auth/actions/workflows/pipeline.yml/badge.svg?branch=main)[![Coverage Status](https://camo.githubusercontent.com/dffc9e97feb8f157ea05b7d003b97208f144a992b2a379936f4930d84a25b0fc/68747470733a2f2f636f6465636f762e696f2f67682f6a656b6b302f6a77742d617574682f6272616e63682f6d61696e2f6772617068732f62616467652e737667)](https://codecov.io/gh/jekk0/jwt-auth)[![Latest Stable Version](https://camo.githubusercontent.com/5c5f302e8b31d0234b2ce14455c77488ae2357bd4b1f5a64b48ccf443e8b958f/68747470733a2f2f706f7365722e707567782e6f72672f6a656b6b302f6a77742d617574682f762f737461626c65)](https://packagist.org/packages/jekk0/jwt-auth)[![Total Downloads](https://camo.githubusercontent.com/c0194e545e9e75b38c2592e8e4b006675c63f72141950f5ca54e4fd21af0b212/68747470733a2f2f706f7365722e707567782e6f72672f6a656b6b302f6a77742d617574682f646f776e6c6f616473)](https://packagist.org/packages/jekk0/jwt-auth)[![PHP Version Require](https://camo.githubusercontent.com/2f75b3efbb9fc94b830edad17942b3fb78fd750ffb970833c49da4b981892406/687474703a2f2f706f7365722e707567782e6f72672f6a656b6b302f6a77742d617574682f726571756972652f706870)](https://packagist.org/packages/jekk0/jwt-auth)

Installation
------------

[](#installation)

```
composer require jekk0/jwt-auth
```

Optionally, install the paragonie/sodium\_compat package from composer if your php env does not have libsodium installed:

```
composer require paragonie/sodium_compat
```

Package configuration
---------------------

[](#package-configuration)

### Publish package resources

[](#publish-package-resources)

```
php artisan vendor:publish --provider=Jekk0\JwtAuth\JwtAuthServiceProvider
```

After running this command, resources from the package, such as the configuration file and migrations, will be added to your Laravel application.

### Configure package (optional)

[](#configure-package-optional)

You should now have a `./config/jwtauth.php` file that allows you to configure the package.

### Create a new table for manage refresh tokens

[](#create-a-new-table-for-manage-refresh-tokens)

Run the migrate command to create the table `jwt_refresh_tokens` needed to store JWT refresh token data

```
php artisan migrate
```

### Generate certificates and add configuration to your .env file

[](#generate-certificates-and-add-configuration-to-your-env-file)

```
$ php artisan jwtauth:generate-certificates

Copy and paste the content below into your .env file:

JWT_AUTH_PUBLIC_KEY=zvZFv5w3DuY3rZK901cnMM8UmV...
JWT_AUTH_PRIVATE_KEY=GaD9g0Xk5QHpzIJOIuEbUEOyJXQSpN...
```

Laravel application configuration
---------------------------------

[](#laravel-application-configuration)

### Configure auth guard

[](#configure-auth-guard)

Make the following changes to the file:

```
// file /config/auth.php

    'guards' => [
-        'web' => [
-            'driver' => 'session',
-            'provider' => 'users',
-        ],
+        'jwt-user' => [
+            'driver' => 'jwt',
+            'provider' => 'users',
+        ],
    ]
```

**A JWT user can be any model that implements the native laravel interface \\Illuminate\\Contracts\\Auth\\Authenticatable**

### Create the user auth controller

[](#create-the-user-auth-controller)

```
php artisan make:controller UserAuthController
```

```
// app/Http/Controllers/UserAuthController.php
