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

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

digitickets/jwt
===============

Provides classes for creating and parsing JWTs.

1.0.1(3mo ago)02MITPHPPHP &gt;=7.3CI passing

Since Mar 13Pushed 3mo agoCompare

[ Source](https://github.com/digitickets/jwt)[ Packagist](https://packagist.org/packages/digitickets/jwt)[ RSS](/packages/digitickets-jwt/feed)WikiDiscussions main Synced 3w ago

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

digitickets/jwt
===============

[](#digiticketsjwt)

A small library for creating and parsing signed JWTs. Supports PHP 7.3 and above, and uses the `firebase/php-jwt` library under the hood.

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

[](#installation)

```
composer require digitickets/jwt
```

Usage
-----

[](#usage)

### 1. Create a config implementing `JwtConfigInterface`

[](#1-create-a-config-implementing-jwtconfiginterface)

Create a config class that provides the signing key and default token lifetime:

```
use DigiTickets\Jwt\Config\JwtConfigInterface;
use Firebase\JWT\Key;

class MyJwtConfig implements JwtConfigInterface
{
    public function getKey(): Key
    {
        return new Key($_ENV['MY_JWT_SECRET'], 'HS256');
    }

    public function getDefaultExpiresInMinutes(): int
    {
        return 1;
    }
}
```

### 2. Create a JWT

[](#2-create-a-jwt)

```
use DigiTickets\Jwt\JwtClaims;
use DigiTickets\Jwt\JwtData;
use DigiTickets\Jwt\JwtFactory;

$token = JwtFactory::createJwt(
    new MyJwtConfig(), // The config created in step 1.
    new JwtData([
        JwtClaims::AUDIENCE => 'my-service',
    ])
);

var_dump($token); // string(153) "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3NzM0MzU5NjEsImV4cCI6MTc3MzQzNjAyMSwiYXVkIjoibXktc2VydmljZSJ9.7Y8Sr7RL9w453TuSpC-j5u8ZicbN6QSUtInu6xc2VpA"
```

Pass an explicit expiry in minutes as the third argument, or `0` for a non-expiring token:

```
// Expires in 30 days
$token = JwtFactory::createJwt($config, $jwtData, 1440 * 30);

// Never expires
$token = JwtFactory::createJwt($config, $jwtData, 0);
```

### 3. Parse and verify a token

[](#3-parse-and-verify-a-token)

```
use DigiTickets\Jwt\JwtParser;

$data = JwtParser::parseJwt($config, $token);

$data->get('aud');           // 'my-service'
$data->getIssuedAt();        // DateTime
$data->getExpirationTime();  // DateTime

print_r($data);
// Output:
// DigiTickets\Jwt\JwtData Object
// (
//    [data:DigiTickets\Jwt\JwtData:private] => Array
//        (
//            [iat] => 1773435961
//            [exp] => 1773436021
//            [aud] => my-service
//        )
//
// )
```

Throws a `Firebase\JWT` exception if the token is invalid, expired, or has a bad signature.

Testing
-------

[](#testing)

Because we are supporting an old version of PHP, it's advisable to run tests in a Docker container so we use the correct PHP version.

```
./shell.sh
# Inside the container:
composer install
composer test

```

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance81

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity30

Early-stage or recently created project

 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 ~0 days

Total

2

Last Release

102d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/23523887?v=4)[DigiTickets](/maintainers/DigiTickets)[@digitickets](https://github.com/digitickets)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[google/auth

Google Auth Library for PHP

1.4k286.7M205](/packages/google-auth)[stevenmaguire/oauth2-keycloak

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

2276.2M36](/packages/stevenmaguire-oauth2-keycloak)[robsontenorio/laravel-keycloak-guard

🔑 Simple Keycloak Guard for Laravel

5181.1M3](/packages/robsontenorio-laravel-keycloak-guard)[ellaisys/aws-cognito

AWS Cognito package that allows Auth and other related features using the AWS SDK for PHP

121242.9k1](/packages/ellaisys-aws-cognito)[microsoft/kiota-authentication-phpleague

Authentication provider for Kiota using the PHP League OAuth 2.0 client to authenticate against the Microsoft Identity platform

153.8M9](/packages/microsoft-kiota-authentication-phpleague)[rainlab/user-plugin

User plugin for October CMS

11854.7k15](/packages/rainlab-user-plugin)

PHPackages © 2026

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