It is a project in which the possibility of registering, login and editing users and controlling the access level of users has been implemented. In this project, by passport scope, three types of roles are envisaged(superAdmin,admin,basic), and each of which has a specific level of access. Therefore, each token that is created has a specific access level.
composer install
php artisan key:generate
php artisan config:cache
php artisan migrate
#4 You should execute the passport:install Artisan command. This command will create the encryption keys needed to generate secure access tokens .
composer require laravel/passport
php artisan passport:install
php artisan db:seed
php artisan serve
curl -X POST "http://localhost/api/v1/auth/register" -H "Content-Type: application/json" -H "Accept: application/json" -d '{"name": "your name", "email": "your email", "password": "your password", "password_confirmation": "your password"}'
{
"message": "User creation is successful!",
"user": {
"id": ?,
"name": "Your name",
"email": "Your email",
"created_at": "create datetime",
"updated_at": "update dateTime"
},
"token": "eyJ0eXAiO.........."
}
curl -X POST "http://localhost/api/v1/auth/login" -H "Content-Type: application/json" -H "Accept: application/json" -d '{"email": "your email", "password": "your password"}'
{
"message": "Successful login!",
"user": {
"name": "your name",
"email": "your email"
},
"token": "eyJ0eXAiO.........."
}
curl -X GET "http://localhost:8000/api/v1/user/usersList" -H "Accept: application/json" -H "Authorization: Bearer token"
{
"message": "Successful get user info",
"data": [
{
"id": ?,
"name": "User name",
"email": "User email address",
"created_at": "create datetime",
"updated_at": "update dateTime"
},
.
.
.
]
}
curl -X GET "http://localhost:8000/api/v1/user/getUser/?" -H "Content-Type: application/json" -H "Accept: application/json" -H "Authorization: Bearer token"
{
"message": "Successful get user info",
"data": {
"id": ?,
"name": "User name",
"email": "User email address",
"created_at": "create datetime",
"updated_at": "update dateTime"
}
]
}
curl -X GET "localhost:8000/api/v1/user/update/?" -H "Content-Type: application/json" -H "Accept: application/json" -H "Authorization: Bearer token" -d '{"name": "Your name", "password": "your password"}'
{
{
"message": "Successfull update info."
}
}
curl -X DELETE "http://localhost/api/v1/user/delete/?" -H "Content-Type: application/json" -H "Accept: application/json" -H "Authorization: Bearer token"
{
{
"message": "Successfull delete user"
}
}
curl -X GET "http://localhost:8000/api/v1/role/change/3" -H "Content-Type: application/json" -H "Accept: application/json" -H "Authorization: Bearer token" -d '{"role": "admin"}'
{
"message": "Successfull update role."
}