简体   繁体   English

如何在Loopback 3中定义管理员角色?

[英]How can I define admin role in Loopback 3?

I have this model in customers.json, acls: 我在customers.json中有这个模型,acls:

"acls": [
{
  "accessType": "*",
  "principalType": "ROLE",
  "principalId": "$everyone",
  "permission": "DENY"
},
{
  "accessType": "READ",
  "principalType": "ROLE",
  "principalId": "admin",
  "permission": "ALLOW",
  "through": "RoleMapping"
}
]

And i have this user model base on loopback user: 我有这个基于环回用户的用户模型:

{
 "name": "userModel",
 "base": "User",
 ...
}

"relations": {
"roles": {
  "type": "hasMany",
  "model": "Role",
  "foreignKey": "principalId"
}
},

I have defined in http://localhost:3000/explorer in RoleMapping: 我在RoleMapping中的http:// localhost:3000 / explorer中定义了:

{
 "id": "58b82f1dbd7b9f1a601646cf",
 "principalType": "USER",
 "principalId": "58b82ec9bd7b9f1a601646ce",
 "roleId": "5570fb69a1227c8c039293da"
 }

But i always get 401 Unauthorized error when I try to display the customers. 但是当我尝试显示客户时,我总是得到401 Unauthorized错误。 I would be very gradefull if someone could help me. 如果有人可以帮助我,我会非常有资格。

Have you set the Token in the Loopback Explorer? 你在Loopback Explorer中设置了Token吗?

When you enable the ACL in Loopback you must Login using the end-point /user/login 在Loopback中启用ACL时,必须使用end-point / user / login登录

{"username":"john", "password": "abc123"}

Then copy and paste the id from the response into the Token field. 然后将响应中的id复制并粘贴到Token字段中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM