loopback icon indicating copy to clipboard operation
loopback copied to clipboard

ACL seems to be not working: 401 Authorization Required

Open achintverma opened this issue 11 years ago • 6 comments

Hello, I created a Model named "ShippingAddresses" which has following ACL rules.

[
    {
      "accessType": "*",
      "principalType": "ROLE",
      "principalId": "$everyone",
      "permission": "DENY"
    },
    {
      "accessType": "READ",
      "principalType": "ROLE",
      "principalId": "$owner",
      "permission": "ALLOW"
    },
    {
      "accessType": "EXECUTE",
      "principalType": "ROLE",
      "principalId": "$authenticated",
      "permission": "ALLOW",
      "property": "create"
    },
    {
      "accessType": "WRITE",
      "principalType": "ROLE",
      "principalId": "$owner",
      "permission": "ALLOW"
    }
  ]

When I create a record by making a POST call on endpoint /api/shipping_addresses it works perfectly fine but when I make a GET request on same endpoint /api/shipping_addresses it's not working.

Also, just for side note, I have ShippingAddresses model's relation defined with Account (inherits User). Relation is: User -> hasMany ShippingAddress , ShippingAddress -> belongsTo Account.

I read ACL documentation on Loopback Official docs but I'm lost. Everything seems to set correctly but still getting 401: Authorization Required.

achintverma avatar Oct 10 '15 00:10 achintverma

Just so you know, I'm using the same access_token to create record (HTTP POST) as well as for getting records (HTTP GET) so that it doesn't see both requests from different users (owners).

achintverma avatar Oct 10 '15 01:10 achintverma

See my example at https://github.com/strongloop/loopback-example-access-control and the ACL docs at https://docs.strongloop.com/display/public/LB/Authentication%2C+authorization%2C+and+permissions.

For future reference, please post questions to https://groups.google.com/forum/#!forum/loopbackjs. See https://github.com/strongloop/loopback/wiki/Questions for more details.

superkhau avatar Oct 13 '15 23:10 superkhau

That's not helpful. Do you think I didn't go through the links you ping me?

I just asked a very simple question. Can you please see the ACL definition above and tell me why I can create but not update or get?

achintverma avatar Oct 14 '15 01:10 achintverma

@achintverma This is not the correct place to ask questions (Google Groups, StackOverflow and Gitter are the official channels we support as stated in the link I provided you). If you believe this is a legitimate bug, then I will reopen the issue after you provide a sample project. I will then try to reproduce the issue on my end to confirm the bug. See https://github.com/strongloop/loopback/wiki/Reporting-issues#bug-report

superkhau avatar Oct 14 '15 01:10 superkhau

That's not helpful. Do you think I didn't go through the links you ping me?

I just asked a very simple question. Can you please see the ACL definition above and tell me why I can create but not update or get?

I understand you asked asked a simple question, but please read the first line of reporting issues: DO NOT post questions using GitHub issues.

superkhau avatar Oct 14 '15 01:10 superkhau

Have you tried creating a new js file with this:

module.exports = function enableAuthentication(server) {
  server.enableAuth();
};

EmilianoCervantes avatar Nov 11 '17 16:11 EmilianoCervantes