Need help with CodeIgniter-JWT-Sample?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

160 Stars 175 Forks MIT License 16.2K Commits 5 Opened issues


CodeIgniter JWT Sample

Services available


Need anything else?

Contributors list

CodeIgniter-JWT-Sample using CodeIgniter 4

Simple CodeIgniter 4 JWT implementation.

Developers who want to use CodeIgniter 3:

Use following command to switch to CodeIgniter 3 branch

git checkout CI3

Setup using this repo

  • Clone this project on php server XAMPP/WAMP.

  • This project uses Composer as Dependency Manager

  • Use following command to auto install required dependencies

    composer install

  • In

    secret key
    line 23
  • Run or Test code using Postman or any other Rest Client

Setup for existing CodeIgniter 4 project

  • Use composer to manage your dependencies and download PHP-JWT:
  composer require firebase/php-jwt


to your project


add following line at the end of
'authFilter' => \App\Filters\AuthFilter::class,

Add following in

'authFilter' => [
    'before' => [
  • In
    add routes to your Auth controller and resource
$routes->resource('api/auth', ['controller' => 'Auth']);
$routes->resource('api/user', ['controller' => 'User']);
  • In
    add function to return secret key
    public static function getSecretKey()
    return 'example_key';
  • Add logic to generate token in your
    after validating login credentials ``` $key = Services::getSecretKey(); $payload = array( "iss" => "", "aud" => "", "iat" => 1356999524, "nbf" => 1357000000 );

$jwt = JWT::encode($payload, $key); ``` - Run or Test code using Postman or any other Rest Client


Generate auth token using login credentials

URL: http://localhost/CodeIgniter-JWT-Sample/public/index.php/api/auth
Method: POST
Params type: x-www-form-urlencoded
Params: email:same_text

Access resource - User for this example

URL: http://localhost/CodeIgniter-JWT-Sample/public/index.php/api/user
Method: GET
Header Key: Authorization
Value: Bearer 

Project uses

CodeIgniter 4


For any questions mail me [email protected]

GitHub license

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.