Lumen with JWT Authentication, Dingo API and CORS Support
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.
[1] Added via this package.
.git
folder if you get this code via git clone
composer install
php artisan jwt:generate
.env
file for authenticating via databaseAPI_PREFIX
parameter in your .env file (usually api
).php artisan migrate --seed
php -S localhost:8000 -t public/
Or via artisan command:
php artisan serve
To authenticate a user, make a POST
request to /api/auth/login
with parameter as mentioned below:
email: [email protected]
password: johndoe
Request:
curl -X POST -F "[email protected]" -F "password=johndoe" "http://localhost:8000/api/auth/login"
Response:
{
"success": {
"message": "token_generated",
"token": "a_long_token_appears_here"
}
}
GET
request to: /api/auth/user
.Request:
curl -X GET -H "Authorization: Bearer a_long_token_appears_here" "http://localhost:8000/api/auth/user"
Response:
{
"success": {
"user": {
"id": 1,
"name": "John Doe",
"email": "[email protected]",
"created_at": null,
"updated_at": null
}
}
}
PATCH
request to /api/auth/refresh
.DELETE
request to /api/auth/invalidate
.php artisan route:list
⇒ php artisan route:list
+--------+----------------------+---------------------+------------------------------------------+------------------+------------+
| Verb | Path | NamedRoute | Controller | Action | Middleware |
+--------+----------------------+---------------------+------------------------------------------+------------------+------------+
| POST | /api/auth/login | api.auth.login | App\Http\Controllers\Auth\AuthController | postLogin | |
| GET | /api | api.index | App\Http\Controllers\APIController | getIndex | jwt.auth |
| GET | /api/auth/user | api.auth.user | App\Http\Controllers\Auth\AuthController | getUser | jwt.auth |
| PATCH | /api/auth/refresh | api.auth.refresh | App\Http\Controllers\Auth\AuthController | patchRefresh | jwt.auth |
| DELETE | /api/auth/invalidate | api.auth.invalidate | App\Http\Controllers\Auth\AuthController | deleteInvalidate | jwt.auth |
+--------+----------------------+---------------------+------------------------------------------+------------------+------------+
I made a Postman collection here.
Laravel and Lumen is a trademark of Taylor Otwell
Sean Tymon officially holds "Laravel JWT" license
If this project help you reduce time to develop, you can give me a cup of coffee :)