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

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

rootwork/phalcon-jwt
====================

A JWT implementation for Phalcon 2

9920—0%4PHP

Since Aug 4Pushed 9y ago4 watchersCompare

[ Source](https://github.com/rootworkit/phalcon-jwt)[ Packagist](https://packagist.org/packages/rootwork/phalcon-jwt)[ RSS](/packages/rootwork-phalcon-jwt/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Phalcon JWT
===========

[](#phalcon-jwt)

JWT session drop-in for Phalcon 2.

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

[](#installation)

Install composer in a common location or in your project:

```
curl -s http://getcomposer.org/installer | php
```

Create the composer.json file as follows:

```
{
    "require": {
        "rootwork/phalcon-jwt": "dev-master"
    }
}
```

Run the composer installer:

```
php composer.phar install
```

Usage
-----

[](#usage)

### Loading the JWT session service

[](#loading-the-jwt-session-service)

```
$jwtKey = 'c8cb6ae1fb193e1e9d3d2d6553479755bbe59e34e2b965629ee4346e4c4902646c93ccd6cd7fd6d2392f300d251632e64bf1a1c260adf1b7219e8caa6dc7d27e';
$di = new FactoryDefault();

// Load the Jwt session
$di->setShared('session', function () use ($config) {
    $session = new Jwt(['key' => $jwtKey]);
    $session->start();

    return $session;
});
```

### Starting a new session

[](#starting-a-new-session)

```
// In your login controller/action
$session = $this->session;
$session->set('sub', $userId);
$session->write();
```

### Accessing an active session via the user's JWT cookie

[](#accessing-an-active-session-via-the-users-jwt-cookie)

```
// Usually in a security plugin
if ($sub = $this->session->get('sub')) {
    if ($user = Users::findFirstById($sub)) {
        $this->getDi()->setShared('user', $user);
    } else {
        $this->getDi()->getShared('session')->destroy();
    }
}
```

### Ending the session

[](#ending-the-session)

```
// Logging the user out
$this->session->destroy();
```

Generating a secret key
-----------------------

[](#generating-a-secret-key)

Easily done from a PHP prompt.

```
php -a
echo bin2hex(openssl_random_pseudo_bytes(64));
c8cb6ae1fb193e1e9d3d2d6553479755bbe59e34e2b965629ee4346e4c4902646c93ccd6cd7fd6d2392f300d251632e64bf1a1c260adf1b7219e8caa6dc7d27e

```

Then in your code:

```
// In the real world, this would go in your application configuration.
$jwtKey = 'c8cb6ae1fb193e1e9d3d2d6553479755bbe59e34e2b965629ee4346e4c4902646c93ccd6cd7fd6d2392f300d251632e64bf1a1c260adf1b7219e8caa6dc7d27e';
```

About JWTs
----------

[](#about-jwts)

Phalcon JWT uses the Firebase JWT library. To learn more about it and JSON Web Tokens in general, visit:

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 88.9% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/6f2027f895e618ab70939adcfd544205a82cfb11096309b4bc556a6cfc8f6910?d=identicon)[rootwork](/maintainers/rootwork)

---

Top Contributors

[![mikesoule](https://avatars.githubusercontent.com/u/235210?v=4)](https://github.com/mikesoule "mikesoule (8 commits)")[![thinhvoxuan](https://avatars.githubusercontent.com/u/2169723?v=4)](https://github.com/thinhvoxuan "thinhvoxuan (1 commits)")

### Embed Badge

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

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

###  Alternatives

[namshi/jose

JSON Object Signing and Encryption library for PHP.

1.8k99.6M101](/packages/namshi-jose)[league/oauth1-client

OAuth 1.0 Client Library

99698.8M106](/packages/league-oauth1-client)[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[gesdinet/jwt-refresh-token-bundle

Implements a refresh token system over Json Web Tokens in Symfony

70516.4M35](/packages/gesdinet-jwt-refresh-token-bundle)[league/oauth2-google

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

41721.2M118](/packages/league-oauth2-google)[illuminate/auth

The Illuminate Auth package.

9327.3M1.0k](/packages/illuminate-auth)

PHPackages © 2026

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