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

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

nyra/jwt
========

JSON Web Token (JWT) library for PHP

1.0.0-alpha.1(8mo ago)081MITPHPPHP ^8.1

Since Sep 19Pushed 8mo agoCompare

[ Source](https://github.com/nyra-dev/jwt)[ Packagist](https://packagist.org/packages/nyra/jwt)[ RSS](/packages/nyra-jwt/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (2)Used By (1)

Nyra JWT Library
================

[](#nyra-jwt-library)

A lightweight, modern PHP library for working with JSON Web Tokens (JWT), designed for security, extensibility, and clear developer ergonomics.

Features
--------

[](#features)

- **JWT Encoding &amp; Decoding:** Create and validate JWTs, supporting HS256/HS384/HS512 (HMAC), RS256/RS384/RS512 (RSA), and ES256/ES384/ES512 (ECDSA).
- **Key Management:** Flexible key handling via `Key` objects, string keys, OpenSSL keys, or X.509 certificates. Supports key IDs (`kid`) for key rotation.
- **JWK Support:** Convert JSON Web Key (JWK) representations to usable keys via the built-in `JwkConverter`.
- **Strict Validation:** Verifies token structure, signature, algorithm, and key presence. Throws explicit exceptions for invalid tokens, unsupported algorithms, and missing keys.
- **PSR-12 &amp; PSR-4 Compliance:** Clean, namespaced code for easy autoloading and integration.
- **Comprehensive Test Suite:** PHPUnit tests covering all success and failure paths.
- **Zero Dependency (except PHP &amp; OpenSSL):** No external JWT libraries required.
- **Extensible:** Easily add more algorithms, custom claims, or integrate with frameworks.

Getting Started
---------------

[](#getting-started)

### Installation

[](#installation)

```
composer require nyra/jwt
```

### Usage Example

[](#usage-example)

```
use Nyra\Jwt\Jwt;
use Nyra\Jwt\Key;

$payload = ['sub' => 'user123', 'exp' => time() + 3600];
$key = new Key('your-secret-key', 'HS256');

$jwt = Jwt::encode($payload, $key);
// Pass $jwt to clients

$decoded = Jwt::decode($jwt, $key);
// $decoded is an object with your claims (e.g., $decoded->sub)
```

### Advanced: Asymmetric Keys &amp; JWK

[](#advanced-asymmetric-keys--jwk)

```
use Nyra\Jwt\Jwk\JwkConverter;

// Convert a JWK array to a Key object
$jwk = [
    'kty' => 'RSA',
    'n' => 'base64url-encoded-modulus',
    'e' => 'base64url-encoded-exponent',
    'kid' => 'my-key-id'
];
$key = JwkConverter::toKey($jwk, 'RS256');
```

Project Structure
-----------------

[](#project-structure)

- `src/` — Library code (`Nyra\Jwt\*`)
- `tests/` — PHPUnit tests (`Nyra\Jwt\Tests\*`)
- `composer.json` — Metadata, autoload, scripts

Development
-----------

[](#development)

- Run tests: `composer test`
- Install dependencies: `composer install`
- Rebuild autoloader: `composer dump-autoload -o`
- Test specific classes/methods:
    - `vendor/bin/phpunit --filter JwtTest`
    - `vendor/bin/phpunit --filter 'JwtTest::testItEncodesAndDecodesHs256Tokens'`

Coding Standards
----------------

[](#coding-standards)

- PSR-12 code style, PSR-4 autoloading
- Strict types (`declare(strict_types=1)`)
- StudlyCaps for class names, camelCase for methods/properties
- Exceptions end with `Exception`

Exception Handling
------------------

[](#exception-handling)

The library throws specific exceptions for error cases:

- `InvalidTokenStructure`
- `SignatureVerificationFailed`
- `UnsupportedAlgorithm`
- `KeyNotFound`

Catch these to handle JWT errors gracefully.

License
-------

[](#license)

MIT License. See [LICENSE](LICENSE).

Contributing
------------

[](#contributing)

Feel free to open issues and pull requests to improve the library. Follow the coding and testing guidelines described above.

Organization
------------

[](#organization)

Maintained by [nyra-dev](https://github.com/nyra-dev)

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance62

Regular maintenance activity

Popularity5

Limited adoption so far

Community8

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

Unknown

Total

1

Last Release

241d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/03da561a330aa76d1a09096b2ee0c48ee53ca51d62fa0239469d9615b6855733?d=identicon)[ghostzero](/maintainers/ghostzero)

---

Top Contributors

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

---

Tags

jwtphpjwt

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[firebase/php-jwt

A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec.

9.8k445.7M2.1k](/packages/firebase-php-jwt)[lcobucci/jwt

A simple library to work with JSON Web Token and JSON Web Signature

7.5k316.6M895](/packages/lcobucci-jwt)[tymon/jwt-auth

JSON Web Token Authentication for Laravel and Lumen

11.5k49.1M350](/packages/tymon-jwt-auth)[namshi/jose

JSON Object Signing and Encryption library for PHP.

1.8k99.6M101](/packages/namshi-jose)[web-token/jwt-framework

JSON Object Signing and Encryption library for PHP and Symfony Bundle.

94818.9M77](/packages/web-token-jwt-framework)[php-open-source-saver/jwt-auth

JSON Web Token Authentication for Laravel and Lumen

8359.8M53](/packages/php-open-source-saver-jwt-auth)

PHPackages © 2026

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