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

ActiveYii2-extension[Authentication &amp; Authorization](/categories/authentication)

kaabar-jwt/yii2-jwt
===================

The Yii2 JWT extension is a tool for implementing JWT (JSON Web Token) authentication in Yii2 applications. It allows developers to create APIs that require authentication and authorization, ensuring that only authorized users can access certain resources. The extension provides a simple and flexible way to implement JWT authentication in Yii2, using the JWT library and following the JWT specification. It includes support for creating and verifying JWT tokens, as well as handling token expiration and refresh. The Yii2 JWT extension can be easily integrated into any Yii2 application, making it a powerful tool for API authentication and authorization.

332.0k↓23.5%4[1 issues](https://github.com/cpjeslot/kaabar-jwt/issues)PHP

Since Jun 22Pushed 1y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (2)Used By (0)

Kaabar JWT Auth Extension
=========================

[](#kaabar-jwt-auth-extension)

The Yii2 JWT extension is a tool for implementing JWT (JSON Web Token) authentication in Yii2 applications. It allows developers to create APIs that require authentication and authorization, ensuring that only authorized users can access certain resources. The extension provides a simple and flexible way to implement JWT authentication in Yii2, using the JWT library and following the JWT specification. It includes support for creating and verifying JWT tokens, as well as handling token expiration and refresh. The Yii2 JWT extension can be easily integrated into any Yii2 application, making it a powerful tool for API authentication and authorization.

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist kaabar-jwt/yii2-jwt:dev-master

```

or add

```
"kaabar-jwt/yii2-jwt": "dev-master"

```

to the require section of your `composer.json` file.

Implementation Steps
--------------------

[](#implementation-steps)

- Yii2 installed
- An https enabled site is required for the HttpOnly cookie to work cross-site
- A database table for storing RefreshTokens:

```

```

- Add JWT parameters in /config/params.php

```

```

- Add component in configuration in /config/web.php for initializing JWT authentication:

```

```

- Add the authenticator behavior to your controllers
- For AuthController.php we must exclude actions that do not require being authenticated, like login, options (when browser sends the cross-site OPTIONS request).

```

```

- Add the methods generateJwt() and generateRefreshToken() to AuthController.php. We'll be using them in the login/refresh-token actions. Adjust class name for your user model if different.

```
