Giter VIP home page Giter VIP logo

lumen-jwt's Introduction

Lumen with JWT Authentication

Basically this is a starter kit for you to integrate Lumen with JWT Authentication. If you want to Lumen + Dingo + JWT for your current application, please check here.

What's Added

Quick Start

  • Clone this repo or download it's release archive and extract it somewhere
  • You may delete .git folder if you get this code via git clone
  • Run composer install
  • Run php artisan key:generate
  • Run php artisan jwt:generate
  • Configure your .env file for authenticating via database
  • Set the API_PREFIX parameter in your .env file (usually api).
  • Run php artisan migrate --seed

A Live PoC

  • Run a PHP built in server from your root project:
php -S localhost:8000 -t public/

Or via bat file (windows):

run-server

To authenticate a user, make a POST request to /api/auth/login with parameter as mentioned below:

email: [email protected]
password: 123

Request:

curl -X POST -F "[email protected]" -F "password=123" "http://localhost:8000/api/auth/login"

Response:

{
  "success": {
    "message": "Login success",
    "token": "TOKEN_HERE"
  }
}
  • With token provided by above request, you can check authenticated user by sending a GET request to: /api/auth/user.

Request:

curl -X GET -H "Authorization: Bearer TOKEN_HERE" "http://localhost:8000/api/auth/user"

Response:

{
  "success": {
    "user": {
      "id": 1,
      "name": "Ahmad Arif",
      "email": "[email protected]"
    }
  }
}
  • To refresh your token, simply send a PATCH request to /api/auth/refresh.
  • Last but not least, you can also invalidate token by sending a DELETE request to /api/auth/invalidate.
  • To list all registered routes inside your application, you may execute php artisan api:list-route
โ‡’  php artisan api:list-route
+------+----------+---------------------+----------------+-----------------------------------------------------------+---------------------------+-----------+------------+----------+------------+
| Host | Method   | URI                 | Name           | Action                                                    | Middleware                | Protected | Version(s) | Scope(s) | Rate Limit |
+------+----------+---------------------+----------------+-----------------------------------------------------------+---------------------------+-----------+------------+----------+------------+
|      | POST     | api/auth/login      | api.auth.login | App\Http\Controllers\Auth\AuthController@postLogin        | api.controllers           | No        | v1         |          |            |
|      | GET|HEAD | api/auth/user       |                | App\Http\Controllers\Auth\AuthController@getUser          | api.controllers, api.auth | Yes       | v1         |          |            |
|      | GET|HEAD | api                 |                | App\Http\Controllers\APIController@getIndex               | api.controllers, api.auth | Yes       | v1         |          |            |
|      | PATCH    | api/auth/refresh    |                | App\Http\Controllers\Auth\AuthController@patchRefresh     | api.controllers, api.auth | Yes       | v1         |          |            |
|      | DELETE   | api/auth/invalidate |                | App\Http\Controllers\Auth\AuthController@deleteInvalidate | api.controllers, api.auth | Yes       | v1         |          |            |
+------+----------+---------------------+----------------+-----------------------------------------------------------+---------------------------+-----------+------------+----------+------------+

Postman Project

You can use this postman project, please check here

Configuration Environment Logo

Reference

lumen-jwt's People

Contributors

ahmadarif avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

roddyka

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.