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(2y ago)018MITPHP

Since Jun 13Pushed 2y ago1 watchersCompare

[ Source](https://github.com/caylof/php-jwt)[ Packagist](https://packagist.org/packages/caylof/jwt)[ RSS](/packages/caylof-jwt/feed)WikiDiscussions master Synced 1mo 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 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity44

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

1062d 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

[tymon/jwt-auth

JSON Web Token Authentication for Laravel and Lumen

11.5k49.1M344](/packages/tymon-jwt-auth)[league/oauth2-server

A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.

6.6k136.0M247](/packages/league-oauth2-server)[php-open-source-saver/jwt-auth

JSON Web Token Authentication for Laravel and Lumen

8359.8M52](/packages/php-open-source-saver-jwt-auth)[kreait/firebase-tokens

A library to work with Firebase tokens

24040.8M14](/packages/kreait-firebase-tokens)[scheb/2fa

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

578630.7k1](/packages/scheb-2fa)[steverhoades/oauth2-openid-connect-server

An OpenID Connect Server that sites on The PHP League's OAuth2 Server

2097.8M12](/packages/steverhoades-oauth2-openid-connect-server)

PHPackages © 2026

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