authentication - 如何在 Feathers 中“限制所有者”但允许“管理员”角色
问题描述
我使用 feathers-permissions 和 feathers-authentication-hooks 来构建一个 RBAC 系统,但仍然无法实现。我想要的是例如:
- 允许用户仅查看/更新他们自己的帐户。
- 允许管理员查看/更新任何帐户。
before: {
all: [],
find: [authenticate('jwt'), checkPermissions({roles: ['admin']})],
get: [authenticate('jwt'), checkPermissions({roles: ['admin']}), hooks.restrictToOwner({ownerField: '_id'})],
create: [hashPassword()],
update: [hashPassword(), authenticate('jwt'), checkPermissions({roles: ['admin']}), hooks.restrictToOwner({ownerField: '_id'})],
patch: [hashPassword(), authenticate('jwt'), checkPermissions({roles: ['admin']}), hooks.restrictToOwner({ownerField: '_id'})],
remove: [authenticate('jwt'), checkPermissions({roles: ['admin']})]
},
这样管理员仍然无法查看/更新其他帐户。
有什么帮助吗?
解决方案
feathers-permissions
我在->有条件限制角色中找到了答案
此外,是的,最好使用现有的钩子,如feathers-hooks-common
. 但是,如果它不可行,那么您始终可以创建适合您需求的自己的钩子。
推荐阅读
- python - bisect.bisect 与 Python 中的 bisect.bisect_right 不同吗?
- javascript - 使用角度模糊时的新数组
- r - 如何从 R 中的数据框中选择一定数量的行
- javascript - 具有相同 ID 的两个元素 - 试图找出我可以更改的内容
- php - 如果来自 2 个不同 MYSQLi 列的 2 个不同字符串匹配,则使用 PHP 计算不同列的每个 ID
- machine-learning - 更改输入大小时如何调整机器学习模型输出层?
- python - 如何在数据子集的组合上对 pandas 数据框应用统计测试(函数)
- swift - Swift Decodable Class 不符合
- typescript - 打字稿:“如果这是故意的,请先将表达式转换为‘未知’。”
- c# - selenium incognito 无法单击元素或链接 c#