All Projects → ParitoshVaidya → Codeigniter Jwt Sample

ParitoshVaidya / Codeigniter Jwt Sample

Licence: mit
CodeIgniter JWT Sample

Projects that are alternatives of or similar to Codeigniter Jwt Sample

Node Express Mongoose Passport Jwt Rest Api Auth
Node, express, mongoose, passport and JWT REST API authentication example
Stars: ✭ 146 (+1.39%)
Mutual labels:  rest-api, rest, restful-api, restful, jwt
Http Fake Backend
Build a fake backend by providing the content of JSON files or JavaScript objects through configurable routes.
Stars: ✭ 253 (+75.69%)
Mutual labels:  rest-api, rest, restful-api, restful
Restfm
RESTful web services for FileMaker server.
Stars: ✭ 76 (-47.22%)
Mutual labels:  rest-api, rest, restful-api, restful
Api Strategy
Equinor API Strategy
Stars: ✭ 56 (-61.11%)
Mutual labels:  rest-api, rest, restful-api, restful
Ssm
👅基于RESTful风格的前后端分离的SSM框架,集成了shiro和swagger等框架
Stars: ✭ 141 (-2.08%)
Mutual labels:  rest-api, rest, restful, jwt
Blogbackendproject
Backend code for my blogs, develop with Django Rest framework.
Stars: ✭ 204 (+41.67%)
Mutual labels:  rest-api, rest, restful-api, restful
Restful Api Design References
RESTful API 设计参考文献列表,可帮助你更加彻底的了解REST风格的接口设计。
Stars: ✭ 4,830 (+3254.17%)
Mutual labels:  rest-api, rest, restful-api, restful
Graphql2rest
GraphQL to REST converter: automatically generate a RESTful API from your existing GraphQL API
Stars: ✭ 181 (+25.69%)
Mutual labels:  rest-api, rest, restful-api, restful
Apidoc
RESTful API 文档生成工具,支持 Go、Java、Swift、JavaScript、Rust、PHP、Python、Typescript、Kotlin 和 Ruby 等大部分语言。
Stars: ✭ 785 (+445.14%)
Mutual labels:  rest-api, rest, restful-api, restful
Ngx Restangular
Restangular for Angular 2 and higher versions
Stars: ✭ 787 (+446.53%)
Mutual labels:  rest-api, rest, restful-api, restful
Gen
Converts a database into gorm structs and RESTful api
Stars: ✭ 825 (+472.92%)
Mutual labels:  rest-api, rest, restful-api, restful
Generator Http Fake Backend
Yeoman generator for building a fake backend by providing the content of JSON files or JavaScript objects through configurable routes.
Stars: ✭ 49 (-65.97%)
Mutual labels:  rest-api, rest, restful-api, restful
Cerberus
A demonstration of a completely stateless and RESTful token-based authorization system using JSON Web Tokens (JWT) and Spring Security.
Stars: ✭ 482 (+234.72%)
Mutual labels:  rest-api, rest, restful-api, jwt
Rest Api Design Guide
NBB's REST-ish API Design Guide
Stars: ✭ 643 (+346.53%)
Mutual labels:  rest-api, rest, restful-api, restful
Farwest
Framework for building RESTful HATEOAS-driven applications.
Stars: ✭ 18 (-87.5%)
Mutual labels:  rest-api, rest, restful-api, restful
Calm
It is always Calm before a Tornado!
Stars: ✭ 50 (-65.28%)
Mutual labels:  rest-api, rest, restful-api, restful
Graceful
Elegant Python REST toolkit built on top of falcon
Stars: ✭ 73 (-49.31%)
Mutual labels:  rest-api, restful-api, restful
Jersey Jwt
Example of REST API with JWT authentication using Jersey, Jackson, Undertow, Weld, Hibernate and Arquillian.
Stars: ✭ 131 (-9.03%)
Mutual labels:  rest-api, rest, jwt
Openapi Generator
OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
Stars: ✭ 10,634 (+7284.72%)
Mutual labels:  rest-api, rest, restful-api
Api Generator
Api Generator是一款可以自动解析Controller类抽取REST接口信息并自动上传YApi的IDEA插件。YApi好伴侣,从此维护文档再也不是事儿了!
Stars: ✭ 139 (-3.47%)
Mutual labels:  rest-api, rest, restful-api

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] (https://getcomposer.org/) as Dependency Manager

  • Use following command to auto install required dependencies

    composer install

  • In /app/Config/Services.php change secret key at 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

Copy app/Filters/AuthFilter.php to your project

In /app/Config/Filters.php add following line at the end of $aliases array

'authFilter' => \App\Filters\AuthFilter::class,

Add following in $filters array

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

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

Run

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
        password: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 <Token value from above call>

Project uses

[CodeIgniter 4] (https://www.codeigniter.com/)
[php-jwt] (https://github.com/firebase/php-jwt)

Contact

For any questions mail me [email protected]

GitHub license

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].