0
votes

I have loopback app and I have model name photo. I working on my local host and try to Post in Photos model and it's working fine. However, when I build it and try to POST on online server I get authorization required error.

My acl look like this:

"acls": [
{
  "accessType": "*",
  "principalType": "ROLE",
  "principalId": "$everyone",
  "permission": "DENY"
},
{
  "accessType": "*",
  "principalType": "ROLE",
  "principalId": "admin",
  "permission": "ALLOW"
},
{
  "accessType": "*",
  "principalType": "ROLE",
  "principalId": "$owner",
  "permission": "ALLOW"
},
{
  "accessType": "EXECUTE",
  "principalType": "ROLE",
  "principalId": "$everyone",
  "permission": "ALLOW",
  "property": "findById"
},
{
  "accessType": "EXECUTE",
  "principalType": "ROLE",
  "principalId": "$everyone",
  "permission": "ALLOW",
  "property": "__get__comments"
},
{
  "accessType": "EXECUTE",
  "principalType": "ROLE",
  "principalId": "$everyone",
  "permission": "ALLOW",
  "property": "__count__comments"
},
{
  "accessType": "EXECUTE",
  "principalType": "ROLE",
  "principalId": "$everyone",
  "permission": "ALLOW",
  "property": "__get__likes"
},
{
  "accessType": "EXECUTE",
  "principalType": "ROLE",
  "principalId": "$everyone",
  "permission": "ALLOW",
  "property": "__count__likes"
},
{
  "accessType": "EXECUTE",
  "principalType": "ROLE",
  "principalId": "$authenticated",
  "permission": "ALLOW",
  "property": "__create__comments"
},
{
  "accessType": "EXECUTE",
  "principalType": "ROLE",
  "principalId": "$everyone",
  "permission": "ALLOW",
  "property": "find"
},
{
  "accessType": "EXECUTE",
  "principalType": "ROLE",
  "principalId": "$authenticated",
  "permission": "ALLOW",
  "property": "create"
}
2
I think you should first, test the route without any ACL. If it works, then you can go to the next step and add ACL. Could you include your route and its parameter as well? - Maryam Saeidi

2 Answers

0
votes

First, some cleanup: you can combine many similar ACLSs into a single block:

{
  "accessType": "EXECUTE",
  "principalType": "ROLE",
  "principalId": "$everyone",
  "permission": "ALLOW",
  "property": [
    "find",
    "findById",
    "__get__likes",
    "__get__comments",
    "__count__likes",
    "__count__comments"
    ]
},

... and second: are you logged in when attempting to make your request on your server? Check that the 'authorization' token is being sent and is good. Same database or different database from your localhost?

0
votes

You can check the ACL which is applied to a route by enabling the following debug option:

DEBUG=loopback:security:acl

I used this log to solve my problems in configuring ACL.

Please check this link for more information:

https://loopback.io/doc/en/lb2/Setting-debug-strings.html#using-debug-strings