PHPackages                             controlabs/jwt-helper - 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. controlabs/jwt-helper

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

controlabs/jwt-helper
=====================

Helper to generate JWT using firebase/php-jwt in a simplified way

v1.0.2(7y ago)21421MITPHPPHP ^7.1

Since Oct 25Pushed 7y ago1 watchersCompare

[ Source](https://github.com/controlabs/php-jwt-helper)[ Packagist](https://packagist.org/packages/controlabs/jwt-helper)[ RSS](/packages/controlabs-jwt-helper/feed)WikiDiscussions master Synced 4d ago

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

php-jwt-helper
==============

[](#php-jwt-helper)

[![Build Status](https://camo.githubusercontent.com/7f6fd1436605d7b3ce2dbd88d50e033bef72765eeb994495efc1854347c0696a/68747470733a2f2f7472617669732d63692e6f72672f636f6e74726f6c6162732f7068702d6a77742d68656c7065722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/controlabs/php-jwt-helper)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/27bf09b759a660c21536d25358b4418a32487bcc5d91a56912579057aa570890/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f636f6e74726f6c6162732f7068702d6a77742d68656c7065722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/controlabs/php-jwt-helper/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/9b177e4e0b39610b001362119bf88b5875896938503478dd0ba686cb1714d7db/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f636f6e74726f6c6162732f7068702d6a77742d68656c7065722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/controlabs/php-jwt-helper/?branch=master)[![Build Status](https://camo.githubusercontent.com/1da08256fbc633d852a705ea77c5b189f37e8861e23cdbdf7544c8a15382f1c9/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f636f6e74726f6c6162732f7068702d6a77742d68656c7065722f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/controlabs/php-jwt-helper/build-status/master)[![Code Intelligence Status](https://camo.githubusercontent.com/22757df947ecce6bc5dbdd6a1a26325d7a43835755dc4f6cc9fbcbe34f852f4d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f636f6e74726f6c6162732f7068702d6a77742d68656c7065722f6261646765732f636f64652d696e74656c6c6967656e63652e7376673f623d6d6173746572)](https://scrutinizer-ci.com/code-intelligence)[![PHPStan](https://camo.githubusercontent.com/441b5874ce4df0a2defc892979c96c46889b69cb32119d04f0b48626349f8bc9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d656e61626c65642d627269676874677265656e2e7376673f7374796c653d666c6174)](https://github.com/phpstan/phpstan)

[![License](https://camo.githubusercontent.com/338c3c62dcc0982a8425fe2d05a4d84ac0d2242185b968278ca023e873dde1c8/68747470733a2f2f706f7365722e707567782e6f72672f636f6e74726f6c6162732f6a77742d68656c7065722f6c6963656e7365)](https://packagist.org/packages/controlabs/jwt-helper)[![Latest Stable Version](https://camo.githubusercontent.com/6e1b293aff78b40b7276f51c189cb95f5cabdfa8258ebe513080cf6b99e25c10/68747470733a2f2f706f7365722e707567782e6f72672f636f6e74726f6c6162732f6a77742d68656c7065722f762f737461626c65)](https://packagist.org/packages/controlabs/jwt-helper)[![Latest Unstable Version](https://camo.githubusercontent.com/ffa3a67e02e6b04abe01e893ce22f19a4d70cff075461f000393e21cd8595874/68747470733a2f2f706f7365722e707567782e6f72672f636f6e74726f6c6162732f6a77742d68656c7065722f762f756e737461626c65)](https://packagist.org/packages/controlabs/jwt-helper)[![composer.lock](https://camo.githubusercontent.com/d0b6a3f5561dcad44760179f128a31283b3f57d843eedf95cd7dbdfaf3c04252/68747470733a2f2f706f7365722e707567782e6f72672f636f6e74726f6c6162732f6a77742d68656c7065722f636f6d706f7365726c6f636b)](https://packagist.org/packages/controlabs/jwt-helper)[![Total Downloads](https://camo.githubusercontent.com/3049c211e25d1a413b1826010ea1cb4b58d82f5ca5759f763ab008ad5a39cabb/68747470733a2f2f706f7365722e707567782e6f72672f636f6e74726f6c6162732f6a77742d68656c7065722f646f776e6c6f616473)](https://packagist.org/packages/controlabs/jwt-helper)

Helper to generate JWT using firebase/php-jwt in a simplified way.

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

[](#installation)

```
composer require controlabs/jwt-helper

```

Usage
-----

[](#usage)

##### Load private and public keys

[](#load-private-and-public-keys)

```
define('PRIVATE_KEY', file_get_contents('path-to-private-key.pem'));
define('PUBLIC_KEY', file_get_contents('path-to-public-key.pem'));
```

##### Generating JWT string

[](#generating-jwt-string)

```
use Controlabs\Helper\JWT as JWTHelper;

$iss = 'https://controlabs.github.io'; // issuer
$aud = 'https://controlabs.github.io'; // audition string
$sub = 'controlabs'; // subject
$exp = '+ 10 days'; // 'expiration constraint'

$claims = [ //public claims
    'user_id' => '7b1ded55-67bb-4c42-971d-814e15ba8c05',
    'group_id' => '2065b625-3f0e-4dda-98ed-5d48956f5ee6',
    'user_agent' => $_SERVER['HTTP_USER_AGENT'],
    'remote_addr' => $_SERVER['REMOTE_ADDR']
];

$helper = new JWTHelper(PRIVATE_KEY, PUBLIC_KEY);

$token = $helper->encode($iss, $aud, $sub, $exp, $claims);

echo json_encode([
    'token' => $token
]);
```

##### Decoding JWT string

[](#decoding-jwt-string)

```
use Controlabs\Http\Exception\Unauthorized; // composer require controlabs/http-exceptions (optional)
use Controlabs\Helper\JWT as JWTHelper;

$helper = new JWTHelper(PRIVATE_KEY, PUBLIC_KEY);

try {
    $payload = $helper->decode($_POST['token']);
} catch(ExpiredToken $exception) {
    throw new Unauthorized('Inalid token');
}

// or use $helper->decode($_POST['token'], true) to supress errors

if($payload['user_agent'] !== $_SERVER['HTTP_USER_AGENT']) {
    throw new Unauthorized('User agent is invalid.');
}

echo json_encode([
    'user_id' => $payload['user_id'],
    'group_id' => $payload['group_id']
]);
```

##### Extracting payload without decode validations

[](#extracting-payload-without-decode-validations)

```
use Controlabs\Helper\JWT as JWTHelper;

$helper = new JWTHelper(PRIVATE_KEY, PUBLIC_KEY);

// Use only for logs or specific purposes because it extracts content without validating the token.
$payload = $helper->payload($_POST['token']);

echo json_encode([
    'user_id' => $payload['user_id'],
    'group_id' => $payload['group_id']
]);
```

License
-------

[](#license)

This software is open source, licensed under the The MIT License (MIT). See [LICENSE](https://github.com/controlabs/php-jwt-helper/blob/master/LICENSE) for details.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 81.8% 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 ~0 days

Total

3

Last Release

2758d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/43862284?v=4)[Controlabs](/maintainers/controlabs)[@controlabs](https://github.com/controlabs)

---

Top Contributors

[![carlosrodriguesf](https://avatars.githubusercontent.com/u/16665616?v=4)](https://github.com/carlosrodriguesf "carlosrodriguesf (9 commits)")[![martinusso](https://avatars.githubusercontent.com/u/158559?v=4)](https://github.com/martinusso "martinusso (2 commits)")

---

Tags

firebasehelperjwtphp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/controlabs-jwt-helper/health.svg)

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

###  Alternatives

[google/auth

Google Auth Library for PHP

1.4k272.7M162](/packages/google-auth)[thenetworg/oauth2-azure

Azure Active Directory OAuth 2.0 Client Provider for The PHP League OAuth2-Client

2509.6M48](/packages/thenetworg-oauth2-azure)[stevenmaguire/oauth2-keycloak

Keycloak OAuth 2.0 Client Provider for The PHP League OAuth2-Client

2275.9M27](/packages/stevenmaguire-oauth2-keycloak)[robsontenorio/laravel-keycloak-guard

🔑 Simple Keycloak Guard for Laravel

5161.1M3](/packages/robsontenorio-laravel-keycloak-guard)[patrickbussmann/oauth2-apple

Sign in with Apple OAuth 2.0 Client Provider for The PHP League OAuth2-Client

1132.5M6](/packages/patrickbussmann-oauth2-apple)[wp-graphql/wp-graphql-jwt-authentication

JWT Authentication for WPGraphQL

361118.4k1](/packages/wp-graphql-wp-graphql-jwt-authentication)

PHPackages © 2026

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