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

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

ngochip/micro-jwt
=================

Yii2 micro service component for auth

1.0.2(8y ago)0171MITPHPPHP ^5.6 || ^7.0

Since Nov 10Pushed 8y ago1 watchersCompare

[ Source](https://github.com/ngochip/micro-jwt)[ Packagist](https://packagist.org/packages/ngochip/micro-jwt)[ RSS](/packages/ngochip-micro-jwt/feed)WikiDiscussions master Synced today

READMEChangelog (3)Dependencies (2)Versions (4)Used By (0)

micro-jwt
=========

[](#micro-jwt)

jwt for Yii2

This extension provides the [JWT](https://github.com/lcobucci/jwt) integration for the [Yii framework 2.0](http://www.yiiframework.com) (requires PHP 5.5+). It includes basic HTTP authentication support.

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

[](#installation)

Package is available on [Packagist](https://packagist.org/packages/ngochip/micro-jwt), you can install it using [Composer](http://getcomposer.org).

```
composer require ngochip/micro-jwt
```

### Dependencies

[](#dependencies)

- PHP 5.5+
- OpenSSL Extension
- [sizeg/yii2-jwt](https://github.com/sizeg/yii2-jwt)
- [yiisoft/yii2-redis](https://github.com/yiisoft/yii2-redis)

Basic usage
-----------

[](#basic-usage)

1. Create RSA key:

```
openssl genrsa -des3 -out private.pem 2048

Enter pass phrase for private.pem: [YOUR_PASSPARSE]
Verifying - Enter pass phrase for private.pem:[YOUR_PASSPARSE]
```

Export the RSA Public Key to a File

```
openssl rsa -in private.pem -outform PEM -pubout -out public.pem
```

Exports the Private Key to PEM File

```
openssl rsa -in private.pem -out private_unencrypted.pem -outform PEM
```

2.Add `jwt` component to your configuration file,

In Authorization server:

```
'jwt' => [
      'class' => 'ngochip\jwt\Jwt',
      'privateKey'  => __DIR__.'/../certificate/private.pem', //private key for sign (only setup in authorization server)
      'publicKey'   => __DIR__.'/../certificate/public.pem', //public key for verify in client.
      'passparse'   => '1234', //pass parse private key
      'ttl'       => 60 * 60, //time to live for token
      'ttl_refresh'   => 60 * 90, //time to live for refreshToken
      'redis_config'  => [
        'host'  => '127.0.0.1', // blacklist server address (redis server)
        'port'    => 6379, //redis port
        'database'  => 10,
        'password'  => NULL //password for AUTH redis server
      ]
  ],
```

In Client (other server)

```
'jwt' => [
      'class' => 'ngochip\jwt\Jwt',
      'publicKey'   => __DIR__.'/../certificate/public.pem', //public key for verify in client.
      'ttl'       => 60 * 60, //time to live for token
      'ttl_refresh'   => 60 * 90, //time to live for refreshToken
      'issuer'        => 'http://auth.domain.com/api/', //Auth Server Address.
      'redis_config'  => [
        'host'  => '127.0.0.1', // blacklist server address (redis server)
        'port'    => 6379, //redis port
        'database'  => 10,
        'password'  => NULL //password for AUTH redis server
      ]
  ],
```

### Creating (in Authorization server)

[](#creating-in-authorization-server)

Just use the builder to create a new JWT/JWS tokens:

```
$userInfo = [
  'id' => 1,
  'username' => 'admin',
  'email' => 'admin@domain.com',
  'roles' => ['create_post','delete_user']
];
$token = Yii::$app->jwt->getToken($userInfo); //create token
Yii::$app->jwt->setToken($token); //assign Token
$newToken = Yii::$app->jwt->refreshToken(); //refresh token when expried
```

### Use in other server (public key only)

[](#use-in-other-server-public-key-only)

```
Yii::$app->jwt->getTokenFromHeader(); //get token from Header and set to Object;
Yii::$app->jwt->verify(); //verify token, return bool;
Yii::$app->jwt->getInfo(); //get all info in tokenKey (not verify, only get from token). should be call after verified.
Yii::$app->jwt->getInfo('exp'); //extract claim from token, will return expiry time;
Yii::$app->jwt->getHeader(); //get all header in token.
```

### Verifying

[](#verifying)

We can easily validate if the token is valid (using the previous token as example):

```
Yii::$app->jwt->getTokenFromHeader(); //get token from Header Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9....
Yii::$app->jwt->verify(); //verify token, return true if verify success;
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

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

Total

3

Last Release

3102d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/80670162fa6fe25fcb134ce2d337989c1c35fcbf4f0c986a20c489f08ee1b363?d=identicon)[ngochip](/maintainers/ngochip)

---

Top Contributors

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

---

Tags

jwtyii2ngochip

### Embed Badge

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

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

###  Alternatives

[sizeg/yii2-jwt

JWT based on Icobucci

2001.0M7](/packages/sizeg-yii2-jwt)[bizley/jwt

JWT integration for Yii 2

67425.3k2](/packages/bizley-jwt)[kakadu-dev/yii2-jwt-auth

Extension provide JWT auth for Yii2

105.8k](/packages/kakadu-dev-yii2-jwt-auth)

PHPackages © 2026

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