Code Monkey home page Code Monkey logo

codeigniter-jwt-sample's Introduction

CodeIgniter-JWT-Sample using CodeIgniter 4

Simple Codeigniter 4, REST Server, JWT implementation.

Developers who want to use CodeIgniter 3:

Use following command to switch to CodeIgniter 3 branch

git checkout CI3

Update 1

As per multiple requests, I am adding logic for timeout.
Please check application\controllers\Authtimeout.php for more details.

Note: I did not add logic for expired token replacement after timeout.

Update 2

I upgraded CodeIgniter to v4. The old code (CodeIgniter 3) is available on branch CI3.

Setup using this repo

Set up project on php server (XAMPP/Linux).

$config['encryption_key'] = '';
  • jwt_key in application\config\jwt.php
$config['jwt_key']	= '';
  • For Timeout token_timeout in application\config\jwt.php
$config['token_timeout']	= ;

Setup for existing projects

You will need following files:

/application/config/jwt.php <= Add jwt_key here /application/helpers/authorization_helper.php /application/helpers/jwt_helper.php

In /application/config/autoload.php add

$autoload['helper'] = array('url', 'form', 'jwt', "authorization");
$autoload['config'] = array('jwt');

That's it. You are ready. Add your logic to generate token, eg.

$tokenData = array();
$tokenData['id'] = 1; //TODO: Replace with data for token
$output['token'] = AUTHORIZATION::generateToken($tokenData);

Please reply, if you need additional details. Happy coding!

Run

GET auth token

URL: http://host/CodeIgniter-JWT-Sample/auth/token
Method: GET

Check decoded token

URL: http://host/CodeIgniter-JWT-Sample/auth/token
Method: POST
Header Key: Authorization
Value: Auth token generated in GET call

GET auth token with timeout

URL: http://host/CodeIgniter-JWT-Sample/authtimeout/token
Method: GET

Check decoded token with timeout

URL: http://host/CodeIgniter-JWT-Sample/authtimeout/token
Method: POST
Header Key: Authorization
Value: Auth token generated in GET call of authtimeout controller

Project uses

[CodeIgniter] (https://www.codeigniter.com/)
[REST Server] (https://github.com/chriskacerguis/codeigniter-restserver)
[Reference for JWT implementation] (https://github.com/rmcdaniel/angular-codeigniter-seed)

Contact

For any questions mail me [email protected]

GitHub license

codeigniter-jwt-sample's People

Contributors

narfbg avatar gaker avatar timw4mail avatar ericlbarnes avatar vlakoff avatar toopay avatar alexbilbie avatar jim-parry avatar dchill42 avatar akenroberts avatar it-can avatar aanbar avatar purwandi avatar vkeranov avatar ivantcholakov avatar appleboy avatar kylefarris avatar jjaffeux avatar ahnh avatar razican avatar jdfm avatar robinsowell avatar tiyowan avatar ftwbzhao avatar joelcox avatar ostrolucky avatar davidbarratt avatar galdiolo avatar a-h-abid avatar djwoods avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.