The Authentication With JWT module is a pre-built and maintained module that provides all the necessary functionality for user authentication in a Laravel project. The module includes features such as user registration, login, logout, forgot password, change password, and authentication logging. By using this module, developers can save time and effort in implementing these common authentication features in their projects, while promoting consistency and standardization in module design and implementation.
Laravel freamwork -nWidart/laravel-modules package, Implementing JWT authentication, php 7.2 or higher
Step 1: Install Module Package Library
composer require nwidart/laravel-modules
{
"autoload": {
"psr-4": {
"App\\": "app/",
"Modules\\": "Modules/"
}
}
}
if don't have Modules folder on laravel root then create manually.
git clone https://github.com/Hestabit/AuthWithJWT.git
composer require tymon/jwt-auth
For installation and setup jwt read documents
'jwt.verify' => \Modules\AuthWithJWT\Http\Middleware\JWTMiddleware::class,
'jwt.auth' => 'Tymon\JWTAuth\Middleware\GetUserFromToken',
'jwt.refresh' => 'Tymon\JWTAuth\Middleware\RefreshToken',
- Register
- Login
- Logout
- Fetch User Profile
- Update User Profile
- Forget Password
- Change Password
- Audit Logs
URL:- /api/register
Method:- POST
Request Body:-
Parameter | Type | Required | Description |
---|---|---|---|
name | string | Yes | Name of the user |
Yes | Email of the user | ||
password | string | Yes | Password of the user |
password_confirmation | string | Yes | Confirm Pasword |
URL:- api/login
Method:- POST
Request Body:-
Parameter | Type | Required | Description |
---|---|---|---|
Yes | Email of the user | ||
password | string | Yes | Password of the user |
URL:- api/logout
Method:- GET
Request Body:-
Parameter | Type | Required | Description |
---|---|---|---|
token | string | Yes | JWT Token |
URL:- api/user_profile
Method:- GET
Request Body:-
Parameter | Type | Required | Description |
---|---|---|---|
token | string | Yes | JWT Token |
URL:- api/udpate_user_profile
Method:- PUT
Request Body:-
Parameter | Type | Required | Description |
---|---|---|---|
name | string | Yes | Name of the user |
Yes | Email of the user | ||
token | string | Yes | JWT Token |
URL:- api/forgot-password
Method:- POST
Request Body:- email (email,required)
Parameter | Type | Required | Description |
---|---|---|---|
Yes | Email of the user |
URL:- api/change-password
Method:- POST
old_password (required,string,min:6), password (required,string,min:6), password_confirmation (same as password)
Request Body:-
Parameter | Type | Required | Description |
---|---|---|---|
old_password | string | Yes | Old password of the user |
password | string | Yes | Password of the user |
password_confirmation | string | Yes | Confirm Pasword |
token | string | Yes | JWT Token |
URL:- api/user-logs
Method:- POST
Request Body:-
Parameter | Type | Required | Description |
---|---|---|---|
token | string | Yes | JWT Token |
php artisan test Modules/AuthWithJWT/Tests/Unit/ApiControllerTest.php