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

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

emiljimenez21/laravel-jwt-auth
==============================

A JWT client for applications behind an OIDC or OAuth2.0 identity provider

1.0.0(1y ago)04MITPHPPHP ^8.0

Since Oct 1Pushed 1y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

Laravel JWT Auth
================

[](#laravel-jwt-auth)

---

[![Latest Version on Packagist](https://camo.githubusercontent.com/8adf3f633c0228ebb569a719751854d280db729bfdcb54b503a91dc78d9c5bca/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656d696c6a696d656e657a32312f6c61726176656c2d6a77742d617574682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/emiljimenez21/laravel-jwt-auth)[![Total Downloads](https://camo.githubusercontent.com/3b889365cbf2514751010777c6ad6578a816cac36545640224da99c5b85e0e4e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656d696c6a696d656e657a32312f6c61726176656c2d6a77742d617574682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/emiljimenez21/laravel-jwt-auth)[![GitHub Actions](https://github.com/emiljimenez21/laravel-jwt-auth/actions/workflows/main.yml/badge.svg)](https://github.com/emiljimenez21/laravel-jwt-auth/actions/workflows/main.yml/badge.svg)

This package introduces a JWT based authentication mechanism into your laravel application. It is designed for SPA's that use an OpenID Connect (OIDC) or OAuth 2.0 identity provider with public PKCE-enabled clients.

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

[](#installation)

You can install the package via composer:

```
composer require emiljimenez21/laravel-jwt-auth
```

Basic usage
-----------

[](#basic-usage)

**Step 1:** Place the **public key** you use to sign your JWTs in the `/storage` directory with the filename `oauth_public.key`

**Step 2:** Add the `HasJWT` trait to your user model

```
use EmilJimenez21\LaravelJWTAuth\Traits\HasJWT;

class User extends Authenticatable {
    use HasJWT;
}
```

**Step 3:** Update your api guard in `/config/auth.php` to use the `jwt` driver

```
'guards' => [
    'api' => [
        'driver' => 'jwt',
        'provider' => 'users'
    ]
]
```

**Step 4:** Specify the user resolver in `AppServiceProvider` boot method. Do this when you don't have the user stored in the application.

The user resolver enables your application to use the **bearer token** to make requests to the IDP so you can create and populate the user if they don't exist.

*NOTE: This feature is intended for applications that use a public PKCE flow to generate access tokens on the client from the Idp.*

```
public function boot(): void
{
    /**
     * This code will only be ran when the jwt subject does not exist in this system.
     *
     * The user resolver expects a callable that accepts a ?string $bearerToken and a
     * ?User response. It provides a great way for your application to quickly create
     * users that aren't in the system yet.
     * */
    JWT::setUserResolver(function ($bearerToken) {
        // Call the IDP and get the user profile data
        $response = Http::withHeader('Authorization', "Bearer $bearerToken")
            ->get('http://localhost:8000/api/user');

        // Retrieve the response body
        $contents = $response->getBody()->getContents();

        // Convert the json response to an array
        $userData = json_decode($contents, true);

        // Return a new or existing user
        return User::query()->firstOrCreate([
            'id' => $userData['data']['id']
        ]);
    });
}
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Emil Jimenez](https://github.com/emiljimenez21)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

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

588d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/cd8c0df243541c6c2ded4fe9b998953ee8acc24e20e96d15bf4a238f9f602bcb?d=identicon)[EmilJimenez21](/maintainers/EmilJimenez21)

---

Top Contributors

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

---

Tags

laravel-jwt-authemiljimenez21

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[robsontenorio/laravel-keycloak-guard

🔑 Simple Keycloak Guard for Laravel

5161.1M3](/packages/robsontenorio-laravel-keycloak-guard)[kovah/laravel-socialite-oidc

OpenID Connect OAuth2 Provider for Laravel Socialite

2073.7k](/packages/kovah-laravel-socialite-oidc)[truckersmp/steam-socialite

Laravel Socialite provider for Steam OpenID.

1516.7k](/packages/truckersmp-steam-socialite)[vinkas/firebase-auth-laravel

Firebase Authentication package for Laravel PHP Framework

392.1k](/packages/vinkas-firebase-auth-laravel)[pschocke/laravel-telegram-login-widget

Easily integrate Telegrams login widget into your Laravel application to send Telegram messages

1610.4k](/packages/pschocke-laravel-telegram-login-widget)[kolayik/auth

Kolay Auth

121.9k](/packages/kolayik-auth)

PHPackages © 2026

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