PHPackages                             mmirzaee/yii2-api-boilerplate-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. [HTTP &amp; Networking](/categories/http)
4. /
5. mmirzaee/yii2-api-boilerplate-jwt

ActiveProject[HTTP &amp; Networking](/categories/http)

mmirzaee/yii2-api-boilerplate-jwt
=================================

A Yii2 Boilerplate to create a ready-to-use REST API in seconds

v1.0.2(7y ago)7855[1 issues](https://github.com/mmirzaee/yii2-api-boilerplate-jwt/issues)BSD-3-ClausePHPPHP &gt;=5.4.0

Since Mar 29Pushed 7y ago1 watchersCompare

[ Source](https://github.com/mmirzaee/yii2-api-boilerplate-jwt)[ Packagist](https://packagist.org/packages/mmirzaee/yii2-api-boilerplate-jwt)[ Docs](http://www.yiiframework.com/)[ RSS](/packages/mmirzaee-yii2-api-boilerplate-jwt/feed)WikiDiscussions master Synced 3w ago

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

 [ ![Yii Framework](https://camo.githubusercontent.com/3ce80b354a4b3ac067b0dae30d56e297134afb2a52ec89fc02f03870afcf8106/68747470733a2f2f7777772e7969696672616d65776f726b2e636f6d2f66696c65732f6c6f676f2f7969692e706e67) ](http://www.yiiframework.com/)

Yii2 API Boilerplate with JWT and RBAC
--------------------------------------

[](#yii2-api-boilerplate-with-jwt-and-rbac)

[![Twitter](https://camo.githubusercontent.com/67c97a2cf73f8a97014f9f4bc6b21c7ebfb178aa48412507fe58fa75714877cf/68747470733a2f2f696d672e736869656c64732e696f2f747769747465722f666f6c6c6f772f616c696d6d69727a6165652e7376673f7374796c653d736f6369616c266c6162656c3d466f6c6c6f77)](https://twitter.com/intent/follow?screen_name=alimmirzaee)

Yii2 API Boilerplate is a "starter kit" you can use to build your first API in seconds. As you can easily imagine, it is built on top of the awesome Yii2 Framework.

I used these packages:

- lcobucci/jwt - [lcobucci/jwt](https://github.com/lcobucci/jwt)
- Yii2 JWT - [sizeg/yii2-jwt](https://github.com/sizeg/yii2-jwt)

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

[](#installation)

1. run `composer create-project mmirzaee/yii2-api-boilerplate-jwt project-name`
2. enjoy your coffee ☕

Once the project creation procedure completed, edit db config and run the `./yii migrate` command to create the required tables.

Usage
-----

[](#usage)

1. Edit `config/params.php` and set your own JWT Key and etc.
2. For preparing RBAC try editing `commands/RbacController` and add/edit your own `Roles` and `Permissions`.
3. run `./yii rbac/init` for initializing roles and permissions. This will also create the initial user with username: `root` and password: `ChangeThisPassw0rdTo0` (You can change these in RbacController.php)

Main Features
-------------

[](#main-features)

### Ready-To-Use Authentication Controllers

[](#ready-to-use-authentication-controllers)

You don't have to worry about authentication anymore. I created four controllers you can find in the `controllers/AuthController.php` for those operations.

Try these APIs:

- `POST api/login`, to do the login and get your access token;
- `POST api/refresh`, to refresh an existent access token by getting a new one;
- `POST api/signup`, to create a new user into your application;
- `GET api/auth/me`, to get current user data;

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

[](#configuration)

You can find all the boilerplate specific settings in the `config/params.php` config file.

```
