Jon*_*nny 6 acl loopback relation node.js apiconnect
我想通过loopback获得有关我的用户的一些信息.为此,我创建了一个"user"
与模型相关的"accessToken"
模型,直到现在开启POST /user
,POST开启/user/login
和POST开启/user/logout
.
我补充说 /common/models/user.json
{
"name": "user",
"base": "User",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {},
"validations": [],
"relations": {
"accessTokens": {
"type": "hasMany",
"model": "accessToken",
"foreignKey": "userId"
}
},
"acls": [
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "$authenticated",
"permission": "ALLOW",
"property": "logout"
},
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "findById"
}
],
"methods": {}
}
Run Code Online (Sandbox Code Playgroud)
当我得到GET时,/user/{id}
我得到了:
{
"error": {
"statusCode": 401,
"name": "Error",
"message": "Autorisation requise",
"code": "AUTHORIZATION_REQUIRED",
"stack": "Error: Autorisation requise\n at..."
}
}
Run Code Online (Sandbox Code Playgroud)
我想我不太了解acl/relation
这可能是因为您只$owner
允许findById
:
\n\n\n要限定 $owner,目标模型需要具有与 User 模型(或扩展 User 的模型)的 BelongsTo 关系以及与目标模型实例的外键匹配的属性。仅对路径上具有 \xe2\x80\x98:id\xe2\x80\x99 的远程方法执行 $owner 检查,例如 GET /api/users/:id。
\n
accessToken
的所有者id
user
是您要查找的"principalId": "$owner"
为"principalId": "$authenticated"
,然后您就会知道这是否是您的问题。 归档时间: |
|
查看次数: |
213 次 |
最近记录: |