Skip to content

Instantly share code, notes, and snippets.

@blainsmith
Created February 19, 2015 18:33
Show Gist options
  • Save blainsmith/40d304416b8e576a6fe1 to your computer and use it in GitHub Desktop.
Save blainsmith/40d304416b8e576a6fe1 to your computer and use it in GitHub Desktop.
LoopBack ACL with $owner
{
"name": "Book",
"base": "PersistedModel",
"idInjection": true,
"properties": {
"title": {
"type": "string",
"required": true
},
"value": {
"type": [
"object"
],
"required": true
}
},
"validations": [],
"relations": {
"member": {
"type": "belongsTo",
"model": "Member",
"foreignKey": "memberId"
}
},
"acls": [
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW"
}
],
"methods": []
}
{
"name": "Member",
"base": "User",
"idInjection": true,
"properties": {},
"validations": [],
"relations": {
"books": {
"type": "hasMany",
"model": "Book",
"foreignKey": "memberId"
}
},
"acls": [],
"methods": []
}
@blainsmith
Copy link
Author

I thought that when posting with an access token that would get translated and automatically used on all the CRUD methods.

So if I had a access token XXX that was for Member with ID: 5 then...

POST /books -H 'Authorization: XXX' -d '{ "title": "Book Title" } would create a book that looks like { "id": 1, "memberId": 5, "title": "Book Title" }

Then if I were to perform GET /books -H 'Authorization: XXX' I would get ONLY the books with "memberId": 5 since they were the owner of the object and created it initially with their own access token.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment