Loopback $ owner不适用于findById

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

Arm*_*mel 0

这可能是因为您只$owner允许findById

\n\n
\n

要限定 $owner,目标模型需要具有与 User 模型(或扩展 User 的模型)的 BelongsTo 关系以及与目标模型实例的外键匹配的属性。仅对路径上具有 \xe2\x80\x98:id\xe2\x80\x99 的远程方法执行 $owner 检查,例如 GET /api/users/:id。

\n
\n\n
    \n
  1. 确保您提供的是该文件accessToken的所有者iduser是您要查找的
  2. \n
  3. 如果您不确定,请尝试将:\n 替换"principalId": "$owner""principalId": "$authenticated",然后您就会知道这是否是您的问题。
  4. \n
\n