簡體   English   中英

Loopback $ owner不適用於findById

[英]Loopback $owner doesn't works for findById

我想通過loopback獲得有關我的用戶的一些信息。 為此我創建了一個與"accessToken" "user"模型相關的"user"模型,直到現在/user的POST, /user/login的POST和/user/logout上的POST正在運行。

我在/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": {}
}

當我在/user/{id}上進行GET時,我得到了:

{
  "error": {
    "statusCode": 401,
    "name": "Error",
    "message": "Autorisation requise",
    "code": "AUTHORIZATION_REQUIRED",
    "stack": "Error: Autorisation requise\n    at..."
  }
}

我想我不太了解acl / relation

這可能是因為您只允許$owner findById

要限定$ owner,目標模型需要與User模型(或擴展User的模型)以及與目標模型實例的外鍵匹配的屬性具有belongsTo關系。 僅針對路徑上具有“:id”的遠程方法執行$ owner的檢查,例如,GET / api / users /:id。

  1. 確保您提供的accessToken是您要查找的userid的所有者。
  2. 如果您不確定,請嘗試替換: "principalId": "$owner" with "principalId": "$authenticated" ,然后您就會知道這是否是您的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM