定制 laravelha/jwt-auth-acl 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

laravelha/jwt-auth-acl

Composer 安装命令:

composer require laravelha/jwt-auth-acl

包简介

JWT Auth ACL

README 文档

README

JWT Auth ACL is a Laravel package to authentication and authorization package.

The middleware ha.acl check if auth user is authorized to access the route and he is authorized when has permission with the same name of the route within any role he has

Install

  • Install packaqe with composer composer require laravelha/jwt-auth-acl
  • Remove default User files:
    • app/User.php
    • database/factories/UserFactory.php
    • database/migrations/2014_10_12_000000_create_users_table.php
  • Publish config php artisan vendor:publish --foce --tag ha-auth-config
  • Publish seeder php artisan vendor:publish --foce --tag ha-auth-seeds
  • Add ha.acl on routes with that you wish check permissions
  • Run php artisan db:seed --class=PermissionsTableSeeder to populate permissions table
  • Run php artisan jwt:secret
  • Set config/l5-swagger.php to read annotations on vendor/laravelha/jwt-auth-acl/src
  • Run php artisan l5-swagger:generate to generate docs

Use

  • Add ha.acl on your protected routes
  • Publish seeder php artisan vendor:publish --foce --tag ha-auth-seeds
  • Run php artisan db:seed --class=PermissionsTableSeeder to populate permissions table

Create roles

Tinker

php artisan tinker
factory(Role::class)->create(['name' => 'Name', 'description' => 'Description'])

GuzzleHttp

$client = new GuzzleHttp\Client(['base_uri' => APP_URL]);
$client->post('/api/roles', [
    'headers' => ['Authorization': 'BEARER '.TOKEN],
    'json' => [
        'name': 'Name',
        'descriptiom': 'Descriptiom',
    ],
]

axios

axios.post('/api/auth/login', {
   email: 'admin@laravelha.com', 
   password: 'password', 
});

axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;

axios.post('/api/auth/roles', {
    name: 'Name',
    description: 'Description'
});

cUrl

curl -X POST "APP_URL/api/auth/login" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"email\": \"admin@laravelha.com\", \"password\": \"password\"}"
curl -X POST "APP_URL/api/auth/roles" -H "accept: application/json" -H "Authorization: Bearer TOKEN" -d "{ \"name\": \"Name\", \"description\": \"Description\"}"

Sync role permissions

Tinker

php artisan tinker
$role = Role::find(ID)
$role->permissions->sync([ID_P1, ID_P2, ID_P3..])

GuzzleHttp

$client = new GuzzleHttp\Client(['base_uri' => APP_URL]);
$client->post('/api/roles', [
    'headers' => ['Authorization': 'BEARER '.TOKEN],
    'json' => [
        'permissions': [ID_P1, ID_P2, ID_P3..]
    ],
]

axios

axios.post('/api/auth/login', {
   email: 'admin@laravelha.com', 
   password: 'password', 
});

axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;

axios.put('/api/auth/roles/' + ID, {
    permissions: [ID_P1, ID_P2, ID_P3..],
});

cUrl

curl -X POST "APP_URL/api/auth/login" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"email\": \"admin@laravelha.com\", \"password\": \"password\"}"
curl -X PUT "APP_URL/api/auth/roles/ID" -H "accept: application/json" -H "Authorization: Bearer TOKEN" -d "{ \"permissions\": \"[ID_P1, ID_P2, ID_P3..]\"}"

Sync user roles

Tinker

php artisan tinker
$user = User::find(ID)
$user->roles->sync([ID_R1, ID_R2, ID_R3..])

GuzzleHttp

$client = new GuzzleHttp\Client(['base_uri' => APP_URL]);
$client->post('/api/users', [
    'headers' => ['Authorization': 'BEARER '.TOKEN],
    'json' => [
        'permissions': [ID_R1, ID_R2, ID_R3..]
    ],
]

axios

axios.post('/api/auth/login', {
   email: 'admin@laravelha.com', 
   password: 'password', 
});

axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;

axios.put('/api/auth/users/' + ID, {
    permissions: [ID_R1, ID_R2, ID_R3..],
});

cUrl

curl -X POST "APP_URL/api/auth/login" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"email\": \"admin@laravelha.com\", \"password\": \"password\"}"
curl -X PUT "APP_URL/api/auth/users/ID" -H "accept: application/json" -H "Authorization: Bearer TOKEN" -d "{ \"roles\": \"[ID_R1, ID_R2, ID_R3..]\"}"

Screenshots

Swagger

统计信息

  • 总下载量: 18
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2020-02-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固