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

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

nextphp/jwt
===========

NextPHP/JWT is a simple library to encode and decode JSON Web Tokens (JWT) in PHP. This library is part of the NextPHP framework and was developed by Vedat Yıldırım. It provides methods to generate, validate, and decode JWT tokens, conforming to the current specifications.

1.0.2(2y ago)07MITPHPPHP ^8.0

Since May 30Pushed 2y ago1 watchersCompare

[ Source](https://github.com/nextphp-projects/oauth)[ Packagist](https://packagist.org/packages/nextphp/jwt)[ Docs](https://github.com/leanphpio/jwt)[ RSS](/packages/nextphp-jwt/feed)WikiDiscussions main Synced today

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

NGJWT
=====

[](#ngjwt)

NGJWT is a simple library to encode and decode JSON Web Tokens (JWT) in PHP. This library is part of the LeanPHP framework and was developed by Vedat Yıldırım. It provides methods to generate, validate, and decode JWT tokens, conforming to the current specifications.

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

[](#installation)

You can install this package via Composer:

```
composer install leanphpio/jwt
```

Usage
-----

[](#usage)

### Generating a JWT

[](#generating-a-jwt)

```
// without composer: require 'NGJWT.php';

// with composer
require 'vendor/autoload.php';

use LeanPHP\JWT\NGJWT;

// Initialize the JWT handler with a secret key
$secret = 'your_secret_key';
$jwt = new NGJWT($secret);

// Example payload
$payload = [
    'user_id' => 1,
    'username' => 'john.doe',
    'email' => 'john.doe@example.com',
    'role' => 'admin',
    'iat' => time(),
    'exp' => time() + 3600 // 1 hour expiration
];

// Generate a JWT
$token = $jwt->generate($payload);
echo "Generated Token: " . $token . "\n";

```

### Authenticating a JWT

[](#authenticating-a-jwt)

```
// Example headers containing the JWT
$headers = [
    'Authorization' => 'Bearer ' . $token
];

// Authenticate the user using the token from the headers
try {
    if ($jwt->authenticate($headers)) {
        $user = NGJWT::getUser();
        echo "Authenticated User: \n";
        print_r($user);
    }
} catch (\Exception $e) {
    echo "Authentication failed: " . $e->getMessage() . "\n";
}

```

### Decoding a JWT

[](#decoding-a-jwt)

```
// Decode the token directly
try {
    $decoded = $jwt->decode($token);
    echo "Decoded Token: \n";
    print_r($decoded);
} catch (\Exception $e) {
    echo "Decoding failed: " . $e->getMessage() . "\n";
}

```

### Example

[](#example)

Here's a more detailed example that demonstrates generating, storing, authenticating, and decoding a JWT.

```
require 'vendor/autoload.php';

use leanphp\jwt\NGJWT;

// Initialize the JWT handler with a secret key
$secret = 'your_secret_key';
$jwt = new NGJWT($secret);

// Example payload
$payload = [
    'user_id' => 1,
    'username' => 'john.doe',
    'email' => 'john.doe@example.com',
    'role' => 'admin',
    'iat' => time(),
    'exp' => time() + 3600 // 1 hour expiration
];

// Generate a JWT
$token = $jwt->generate($payload);
echo "Generated Token: " . $token . "\n\n";

// Simulate storing the token in a database
echo "Storing the token in the database...\n\n";
// Example of database storage logic (not implemented here)
// storeTokenInDatabase($user_id, $token);

// Example headers containing the JWT
$headers = [
    'Authorization' => 'Bearer ' . $token
];

// Authenticate the user using the token from the headers
echo "Authenticating User...\n";
try {
    if ($jwt->authenticate($headers)) {
        $user = NGJWT::getUser();
        echo "Authenticated User: \n";
        print_r($user);
        echo "\n";
    }
} catch (\Exception $e) {
    echo "Authentication failed: " . $e->getMessage() . "\n";
}

// Decode the token directly
echo "Decoding the Token...\n";
try {
    $decoded = $jwt->decode($token);
    echo "Decoded Token: \n";
    print_r($decoded);
    echo "\n";
} catch (\Exception $e) {
    echo "Decoding failed: " . $e->getMessage() . "\n";
}

// Example output separation
echo "\n--------------------------\n";
echo "Example 1: Token Generation\n";
echo "Generated Token: " . $token . "\n";

echo "\n--------------------------\n";
echo "Example 2: Token Authentication\n";
try {
    if ($jwt->authenticate($headers)) {
        $user = NGJWT::getUser();
        echo "Authenticated User: \n";
        print_r($user);
        echo "\n";
    }
} catch (\Exception $e) {
    echo "Authentication failed: " . $e->getMessage() . "\n";
}

echo "\n--------------------------\n";
echo "Example 3: Token Decoding\n";
try {
    $decoded = $jwt->decode($token);
    echo "Decoded Token: \n";
    print_r($decoded);
    echo "\n";
} catch (\Exception $e) {
    echo "Decoding failed: " . $e->getMessage() . "\n";
}

```

License This project is licensed under the MIT License. See the LICENSE file for more details.

Acknowledgements This library is part of the LeanPHP framework and was developed by Vedat Yıldırım.

Contributing If you find any issues or have suggestions for improvements, feel free to open an issue or submit a pull request on GitHub.

This `README.md` provides an overview of the NGJWT library, including installation instructions, usage examples, and detailed explanations of each method. It also includes a complete example demonstrating how to generate, authenticate, and decode JWT tokens. The repository name `php-jwt` is concise and SEO-friendly, making it easier for users to find your project when searching for JWT solutions in PHP.

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

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

Total

3

Last Release

736d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/13311826?v=4)[Vedat Yıldırım](/maintainers/vedatyildirim)[@vedatyildirim](https://github.com/vedatyildirim)

---

Top Contributors

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

---

Tags

phpjwtJSON Web Token

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[auth0/auth0-php

PHP SDK for Auth0 Authentication and Management APIs.

41021.9M91](/packages/auth0-auth0-php)[ellaisys/aws-cognito

Laravel Authentication using AWS Cognito (Web and API)

123256.9k1](/packages/ellaisys-aws-cognito)[griffinledingham/php-apple-signin

A simple library to decode and parse Apple Sign In client tokens.

2052.1M1](/packages/griffinledingham-php-apple-signin)

PHPackages © 2026

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