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

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

caylof/jwt
==========

PHP jwt used by lcobucci/jwt

v1.0.0(3y ago)019MITPHP

Since Jun 13Pushed 3y ago1 watchersCompare

[ Source](https://github.com/caylof/php-jwt)[ Packagist](https://packagist.org/packages/caylof/jwt)[ RSS](/packages/caylof-jwt/feed)WikiDiscussions master Synced 2w ago

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

基于 lcobucci/jwt 库的二次封装
======================

[](#基于-lcobuccijwt-库的二次封装)

Install
-------

[](#install)

```
composer require caylof/jwt
```

Example
-------

[](#example)

### Symmetric algorithm (HMAC using SHA256)

[](#symmetric-algorithm-hmac-using-sha256)

```
use Caylof\Jwt\JwtAlgo;
use Caylof\Jwt\JwtIssuer;
use Caylof\Jwt\JwtParser;
use Caylof\Jwt\JwtSigner;
use Caylof\Jwt\JwtValidator;

/// issue tokens
$jwtSigner = new JwtSigner(JwtAlgo::HS256, random_bytes(32));
$jwtIssuer = new JwtIssuer(
    issuer: 'user-srv',
    subject: 'auth-tkn',
    audiences: ['mbr'],
    claims: [
        'uid' => 1,
        'name' => 'cctv',
    ]
);
$jwtIssuer->setExpires(0, 1);
$token = $jwtIssuer->issue($jwtSigner);
$jwtStr = $token->toString();

/// parse token
$jwtParser = new JwtParser();
$token = $jwtParser->parse($jwtStr);

/// validate token
$jwtValidator = new JwtValidator(
    issuer: 'user-srv',
    subject: 'auth-tkn',
    audience: 'mbr',
);
$validateResult = $jwtValidator->validate($token, $jwtSigner);
$claims = $token->claims()->all();

print_r(compact('jwtStr', 'validateResult', 'claims'));
```

### Asymmetric algorithm (RSA using SHA256)

[](#asymmetric-algorithm-rsa-using-sha256)

```
use Caylof\Jwt\JwtAlgo;
use Caylof\Jwt\JwtIssuer;
use Caylof\Jwt\JwtParser;
use Caylof\Jwt\JwtSigner;
use Caylof\Jwt\JwtValidator;

/// issue tokens
$issueSigner = new JwtSigner(JwtAlgo::RS256, file_get_contents(runtime_path('jwt.private.key')));
$jwtIssuer = new JwtIssuer(
    issuer: 'user-srv',
    subject: 'auth-tkn',
    audiences: ['mbr'],
    claims: [
        'uid' => 1,
        'name' => 'cctv',
    ]
);
$jwtIssuer->setExpires(0, 1);
$token = $jwtIssuer->issue($issueSigner);
$jwtStr = $token->toString();

/// parse token
$jwtParser = new JwtParser();
$token = $jwtParser->parse($jwtStr);

/// validate token
$validateSigner = new JwtSigner(JwtAlgo::RS256, file_get_contents(runtime_path('jwt.public.key')));
$jwtValidator = new JwtValidator(
    issuer: 'user-srv',
    subject: 'auth-tkn',
    audience: 'mbr',
);
$validateResult = $jwtValidator->validate($token, $validateSigner);
$claims = $token->claims()->all();

print_r(compact('jwtStr', 'validateResult', 'claims'));
```

###  Health Score

21

—

LowBetter than 17% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

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

1163d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/84b34fadfd3ea7bbd7067dbeb8101744819f3750b550e094da288132353e00ef?d=identicon)[caylof](/maintainers/caylof)

### Embed Badge

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

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

###  Alternatives

[php-open-source-saver/jwt-auth

JSON Web Token Authentication for Laravel and Lumen

84511.6M67](/packages/php-open-source-saver-jwt-auth)[scheb/2fa

Two-factor authentication for Symfony applications (please use scheb/2fa-bundle to install)

589701.7k2](/packages/scheb-2fa)[scheb/2fa-trusted-device

Extends scheb/2fa-bundle with trusted devices support

366.0M40](/packages/scheb-2fa-trusted-device)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.8M674](/packages/shopware-core)[jeremy379/laravel-openid-connect

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

62473.7k10](/packages/jeremy379-laravel-openid-connect)[drenso/symfony-oidc-bundle

OpenID connect bundle for Symfony

97795.4k4](/packages/drenso-symfony-oidc-bundle)

PHPackages © 2026

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