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

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

daycry/jwt
==========

JWT Token for Codeigniter 4

v2.0.1(2mo ago)15.7k↑66.7%4MITPHPPHP ^8.1CI passing

Since Aug 17Pushed 2mo ago1 watchersCompare

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

READMEChangelog (9)Dependencies (18)Versions (10)Used By (4)

[![Donate](https://camo.githubusercontent.com/604e3db9c8751116b3f765aad0353ec7ded655bbe8aaacbc38d8c4a6b784b3ed/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f446f6e6174652d50617950616c2d677265656e2e737667)](https://www.paypal.com/donate?business=SYC5XDT23UZ5G&no_recurring=0&item_name=Thank+you%21&currency_code=EUR)

JWT for CodeIgniter 4
=====================

[](#jwt-for-codeigniter-4)

A JWT (JSON Web Token) library for CodeIgniter 4, built on top of [`lcobucci/jwt ^4`](https://github.com/lcobucci/jwt).

[![Build Status](https://github.com/daycry/jwt/workflows/PHP%20Tests/badge.svg)](https://github.com/daycry/jwt/actions?query=workflow%3A%22PHP+Tests%22)[![Coverage Status](https://camo.githubusercontent.com/df1c866c16ae41208f6f54e72a8eff1458c26deaebe9e60bacb80d07a5998f00/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6461796372792f6a77742f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/daycry/jwt?branch=master)[![Downloads](https://camo.githubusercontent.com/55e7e5db2c3111947675eefc155746413fe8ffb12f6a3a8bde76b7d05d54d75e/68747470733a2f2f706f7365722e707567782e6f72672f6461796372792f6a77742f646f776e6c6f616473)](https://packagist.org/packages/daycry/jwt)[![GitHub release (latest by date)](https://camo.githubusercontent.com/4b4177bcc5f8551312fb9a26c937f5d081072a816af207470d1f52fbd5a1a24d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6461796372792f6a7774)](https://packagist.org/packages/daycry/jwt)[![GitHub stars](https://camo.githubusercontent.com/8d85623b6cb682f759265c196d3d341b82483c237734edd29e32652c74b8cd0e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6461796372792f6a7774)](https://packagist.org/packages/daycry/jwt)[![GitHub license](https://camo.githubusercontent.com/d3bfb46e3d618b6331e0da7a574d12af4832cb0f8a05403bbfd6b3c1d5988438/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6461796372792f6a7774)](https://github.com/daycry/jwt/blob/master/LICENSE)

---

Requirements
------------

[](#requirements)

- PHP **8.1** or higher
- CodeIgniter **4.x**
- `lcobucci/jwt ^4.0`

---

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

[](#installation)

```
composer require daycry/jwt
```

### Publish the configuration file

[](#publish-the-configuration-file)

```
php spark jwt:publish
```

### Generate a signing key

[](#generate-a-signing-key)

```
php spark jwt:key
```

The key is written automatically to `.env` as `jwt.signer`. Use `--show` to print it without touching the file.

> ⚠️ Never commit `.env` to version control.

---

Quick Start
-----------

[](#quick-start)

```
use Daycry\JWT\JWT;

$jwt = new JWT();

// Encode
$token = $jwt->encode(['user_id' => 42, 'role' => 'admin'], 'user-42');

// Decode & validate
$claims = $jwt->decode($token);

echo $claims->get('data'); // '{"user_id":42,"role":"admin"}'  (compact mode)
echo $claims->get('uid');  // "user-42"
```

---

Configuration
-------------

[](#configuration)

After publishing, edit `app/Config/JWT.php`:

```
