PHPackages                             benbjurstrom/passport-custom-jwt-claims - 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. benbjurstrom/passport-custom-jwt-claims

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

benbjurstrom/passport-custom-jwt-claims
=======================================

Customize JWT claims in Laravel Passport access tokens

0.0.4(8y ago)341.8k14[9 PRs](https://github.com/benbjurstrom/passport-custom-jwt-claims/pulls)MITPHPPHP ^7.0

Since Apr 20Pushed 3y ago1 watchersCompare

[ Source](https://github.com/benbjurstrom/passport-custom-jwt-claims)[ Packagist](https://packagist.org/packages/benbjurstrom/passport-custom-jwt-claims)[ RSS](/packages/benbjurstrom-passport-custom-jwt-claims/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (3)Versions (11)Used By (0)

Laravel Passport Custom JWT Claims
==================================

[](#laravel-passport-custom-jwt-claims)

[![Build Status](https://camo.githubusercontent.com/8207d57e642ab2b5417e6445995a811bcaed2b74893aabb9e757cc6e0e2d86f2/68747470733a2f2f7472617669732d63692e6f72672f62656e626a75727374726f6d2f70617373706f72742d637573746f6d2d6a77742d636c61696d732e737667)](https://travis-ci.org/benbjurstrom/passport-custom-jwt-claims)Customize the JWT claims in [Laravel/Passport](https://github.com/laravel/passport) access tokens

What are JWT claims?
--------------------

[](#what-are-jwt-claims)

All access tokens issued by [Laravel/Passport](https://github.com/laravel/passport) are in fact [JSON web tokens](https://jwt.io/) (JWT). Each token contains a set of claims consisting of JSON key value pairs. Because the token is cryptographically signed using a public/private RSA key pair we can trust that the claims contained in the token were issued by Laravel/Passport.

Here is an example token containing the default Laravel/Passport claims:

```
eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjllNzAxMjhmOTk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fwUofPJNpGqRAkm9l5lcjMVTf2-VYCB7VdREizvg-fidZ9HcYUfSo

```

If we decode the token you get the following JWT payload object:

```
{
  "aud": "c8e104f0-0562-11e7-905b-3d77df97f2f8",
  "jti": "9e70128f990e1ef244af074b43306a4f45beab6553396168228bf876ce01005224fa17937d0f0157",
  "iat": 1489901755,
  "nbf": 1489901755,
  "exp": 1521437755,
  "sub": "c8df99a0-0562-11e7-9082-bfd7aa3311e8",
  "scopes": []
}
```

For reference, the claim `aud` is the Laravel/Passport client\_id that issued the token and the key `sub` refers to the user id in your laravel users table. Note that my client\_id and user\_id columns are UUID data types.

Why would you need custom claims?
---------------------------------

[](#why-would-you-need-custom-claims)

The [OpenID Connect](http://openid.net/connect/) protocol requires JWT claims that are not included in Laravel/Passport access tokens. Adding custom claims allows us to use access tokens issued by Laravel/Passport to authenticate with other services using OpenID Connect. For example, with this package it is possible to use a Laravel/Passport access token to authenticate a laravel user on a [Couchbase Sync Gateway](https://developer.couchbase.com/documentation/mobile/1.4/guides/authentication/openid/index.html)server.

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

[](#installation)

Install the package via composer:

```
composer require benbjurstrom/passport-custom-jwt-claims
```

Add the service provider to the config/app.php providers array.

```
// config/app.php
'providers' => [
    ...
    BenBjurstrom\JwtClaims\JwtClaimsServiceProvider::class
];
```

Do not include `Laravel\Passport\PassportServiceProvider` in your providers array as `JwtClaimsServiceProvider` extends from it.

Configuration
-------------

[](#configuration)

To set your custom claims you must publish the config file:

```
php artisan vendor:publish --provider="JwtClaimsServiceProvider"
```

This is the contents of the published file. Add additional claims as needed.

```
return [

    /*
    |--------------------------------------------------------------------------
    | User Claims
    |--------------------------------------------------------------------------
    |
    | User claims will be loaded from the properties of the auth providers model
    | specified in the auth config file.
    |
    */
    'user_claims' => [
        'name' => 'name',
        'email' => 'email',
    ],

    /*
    |--------------------------------------------------------------------------
    | App claims
    |--------------------------------------------------------------------------
    |
    | App claims are static and will be given the specified value across all
    | tokens issued by the app.
    |
    */
    'app_claims' => [
        'iss' => url('')
    ]

];
```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity54

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

Every ~76 days

Total

4

Last Release

3080d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5c6e87e7d26b161a120d9f149fabc989bf2d5bcccee4e9972867b477d336b92b?d=identicon)[benbjurstrom](/maintainers/benbjurstrom)

---

Top Contributors

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

---

Tags

jwtapilaravelpassportOpenIdOpenID Connectcustomoidcclaims

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/benbjurstrom-passport-custom-jwt-claims/health.svg)

```
[![Health](https://phpackages.com/badges/benbjurstrom-passport-custom-jwt-claims/health.svg)](https://phpackages.com/packages/benbjurstrom-passport-custom-jwt-claims)
```

###  Alternatives

[jeremy379/laravel-openid-connect

OpenID Connect support to the PHP League's OAuth2 Server. Compatible with Laravel Passport.

55342.3k2](/packages/jeremy379-laravel-openid-connect)[auth0/login

Auth0 Laravel SDK. Straight-forward and tested methods for implementing authentication, and accessing Auth0's Management API endpoints.

2745.0M3](/packages/auth0-login)[ronvanderheijden/openid-connect

OpenID Connect support to the PHP League's OAuth2 Server. Compatible with Laravel Passport.

61755.5k](/packages/ronvanderheijden-openid-connect)[corbosman/laravel-passport-claims

Add claims to Laravel Passport JWT Tokens

88655.9k](/packages/corbosman-laravel-passport-claims)[authlete/authlete-laravel

Authlete Library for Laravel

4226.0k](/packages/authlete-authlete-laravel)[authlete/authlete

Authlete Library for PHP

1478.4k1](/packages/authlete-authlete)

PHPackages © 2026

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