All Projects → windhoney → yii2-rest-rbac

windhoney / yii2-rest-rbac

Licence: MIT License
yii2 rbac yii2 rest RBAC Auth manager for Yii2 RESTful(YII2权限管理rbac--rest接口方式)

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to yii2-rest-rbac

yii2-admin-theme
基于Yii2+layui的后台框架模板,实现了完善的RBAC权限控制
Stars: ✭ 87 (+10.13%)
Mutual labels:  yii2, rbac, yii2-admin
Yii2 Ace Admin
我的Yii2 Admin后台项目
Stars: ✭ 130 (+64.56%)
Mutual labels:  yii2, rbac
Rageframe2
一个基于Yii2高级框架的快速开发应用引擎
Stars: ✭ 1,553 (+1865.82%)
Mutual labels:  yii2, rbac
Yii2 Cms
An enterprise application based on yii2 basic template
Stars: ✭ 188 (+137.97%)
Mutual labels:  yii2, rbac
Think Casbin
专为ThinkPHP定制的Casbin的扩展包,Casbin是一个功能强大,高效的开源访问控制库。
Stars: ✭ 138 (+74.68%)
Mutual labels:  restful, rbac
Yii2 Db Rbac
Dynamic control of access rights in YII2
Stars: ✭ 106 (+34.18%)
Mutual labels:  yii2, rbac
Rageframe
基于yii2的应用开发引擎
Stars: ✭ 170 (+115.19%)
Mutual labels:  yii2, rbac
Gui Rbac Yii2
GUI for RBAC Yii2 Auth manager
Stars: ✭ 83 (+5.06%)
Mutual labels:  yii2, rbac
Maxkey
MaxKey is Single Sign On(SSO) System,Leading-Edge Enterprise-Class open source IAM(Identity and Access management) product.
Stars: ✭ 274 (+246.84%)
Mutual labels:  oauth, rbac
Yii2 Authclient
Yii 2 authclient extension.
Stars: ✭ 430 (+444.3%)
Mutual labels:  oauth, yii2
Gin Web
由gin + gorm + jwt + casbin组合实现的RBAC权限管理脚手架Golang版, 搭建完成即可快速、高效投入业务开发
Stars: ✭ 107 (+35.44%)
Mutual labels:  restful, rbac
yii2-league-oauth2-server
Yii 2.0 implementation of PHP league OAuth2 server interfaces
Stars: ✭ 29 (-63.29%)
Mutual labels:  oauth, yii2
Yii2 Swagger
yii2 with swagger-php
Stars: ✭ 138 (+74.68%)
Mutual labels:  yii2, restful
Yii2 Usuario
Highly customizable and extensible user management, authentication, and authorization Yii2 extension
Stars: ✭ 251 (+217.72%)
Mutual labels:  yii2, rbac
examination
Yii2-basic 考试系统
Stars: ✭ 76 (-3.8%)
Mutual labels:  yii2, yii2-admin
yii2-ajaxform
submit ActiveForm via ajax
Stars: ✭ 20 (-74.68%)
Mutual labels:  yii2, yii-extension
rbac
基于rbac设计的权限管理系统
Stars: ✭ 27 (-65.82%)
Mutual labels:  rbac
collection
Basic collection library for Yii Framework 2.0
Stars: ✭ 29 (-63.29%)
Mutual labels:  yii2
lumen-api-skeleton
Lumen API skeleton with JWT to manager tokens, Socialite to OAuth Providers, MongoDB driver and Predis to Redis cache storage.
Stars: ✭ 22 (-72.15%)
Mutual labels:  oauth
oauth
OAuth library for nim
Stars: ✭ 54 (-31.65%)
Mutual labels:  oauth

yii2-rest-rbac

感谢JetBrains对开源软件的支持JetBrains Logo

Yii2权限系统,rest版,根据yii2-admin(https://github.com/mdmsoft/yii2-admin)修改

  • 安装:
composer require windhoney/yii2-rest-rbac

使用

  • 配置oauth2和rbac
   'modules' => [
        'rbac' => [
            'class' => 'wind\rest\Modules'
        ],
        'oauth2' => [
            'class' => 'filsh\yii2\oauth2server\Module',
            //'class' => 'wind\oauth2\Module',相对filsh\yii2\oauth2server做了一点优化,增加了可修改oauth2表的db name
            'tokenParamName' => 'access_token',
            'tokenAccessLifetime' => 3600 * 24,
            'storageMap' => [
                'user_credentials' => 'common\models\User',//可自定义
            ],
            'grantTypes' => [
                'user_credentials' => [
                    'class' => 'OAuth2\GrantType\UserCredentials',
                ],
                'client_credentials' => [
                    'class' => 'OAuth2\GrantType\ClientCredentials',
                ],
                'refresh_token' => [
                    'class' => 'OAuth2\GrantType\RefreshToken',
                    'always_issue_new_refresh_token' => true
                ],
                'authorization_code' => [
                    'class' => 'OAuth2\GrantType\AuthorizationCode'
                ],
            ],
            //选填,oauth2组件版本问题可能导致错误时可添加
            'components' => [
                    'request' => function () {
                        return \filsh\yii2\oauth2server\Request::createFromGlobals();
                    },
                    'response' => [
                        'class' => \filsh\yii2\oauth2server\Response::class,
                    ],
            ],
        ]
    ],
    'components' => [
        'authManager' => [
            'class' => 'wind\rest\components\DbManager', //配置文件
            'defaultRoles' => ['普通员工'] //选填,默认角色(默认角色下->公共权限(登陆,oauth2,首页等公共页面))
            'groupTable' => 'auth_groups',//选填,分组表(已默认,可根据自己表名修改)
            'groupChildTable' => 'auth_groups_child',//选填,分组子表(已默认,可根据自己表名修改)
        ],
        'request' => [
            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
            //'cookieValidationKey' => 'xxxxxxxx',
            'parsers' => [
                'application/json' => 'yii\web\JsonParser',
                'text/json' => 'yii\web\JsonParser',
            ],
        ],
    ]
  • 配置权限
    'as access' => [
        'class' => 'wind\rest\components\AccessControl',
        'allowActions' => [
            'site/*',//允许访问的节点,可自行添加
            'rbac/menu/user-menu',//可将路由配置到“普通员工”(默认角色)下
            'oauth2/*',//可将路由配置到“普通员工”(默认角色)下
        ]
    ],
  • 创建所需要的表
1. 用户表user和菜单表menu
yii migrate --migrationPath=@vendor/windhoney/yii2-rest-rbac/migrations
2. rbac相关权限表
yii migrate --migrationPath=@yii/rbac/migrations/

auth_item 表添加一个字段 parent_name varchar(30) COLLATE utf8_unicode_ci DEFAULT '' COMMENT '父级名称',

3. oauth2相关表
yii migrate --migrationPath=@vendor/filsh/yii2-oauth2-server/migrations
4. 新增分组表
CREATE TABLE `auth_groups` (
  `group_id` varchar(50) NOT NULL COMMENT '分组id',
  `group_name` varchar(100) NOT NULL DEFAULT '' COMMENT '分组名称',
  `group_status` varchar(50) NOT NULL DEFAULT '' COMMENT '状态(开启,关闭)',
  PRIMARY KEY (`group_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='分组';
CREATE TABLE `auth_groups_child` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `group_id` varchar(50) NOT NULL COMMENT '分组id',
  `user_id` varchar(64) NOT NULL COMMENT '用户id',
  PRIMARY KEY (`id`),
  UNIQUE KEY `group_id_2` (`group_id`,`user_id`),
  KEY `group_id` (`group_id`),
  KEY `user_group_id` (`user_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=795 DEFAULT CHARSET=utf8 COMMENT='分组子集';
5. 权限控制相关路由可以参考 example/auth_item_sql 其中包含权限相关的insert语句
INSERT INTO `auth_item` (`name`, `type`, `description`, `rule_name`, `parent_name`, `data`, `created_at`, `updated_at`) VALUES ('/rbac/menu/index', '2', '接口-菜单接口', NULL, '权限控制', '', '1526377735', '1526377269');
INSERT INTO `auth_item` (`name`, `type`, `description`, `rule_name`, `parent_name`, `data`, `created_at`, `updated_at`) VALUES ('/rbac/role/index', '2', '接口-角色接口', NULL, '权限控制', '', '1526377735', '1526377269');
......
  • 添加路由配置
  • 将yii2-rest-rbac/example/rbac_route.php文件内容配置到项目的urlManager的rules规则下
  • 或者在main.php文件中 添加
$dir = __DIR__ . "/route";
$main = wind\rest\helper\RbacHelper::addRoute($dir, $main);
return $main;

并将此文件放到config/route/rbac_route.php

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].