Skip to content

Instantly share code, notes, and snippets.

View francium-lupe's full-sized avatar

francium-lupe

View GitHub Profile
@francium-lupe
francium-lupe / repoadmins4.polar
Created January 17, 2024 22:38
(ReBAC) in Node.js 14
authorized = await oso.authorize(
{ type: 'User', id: 'Bill' },
'edit',
{ type: 'Issue', id: 'tps-reports-99' }
);
console.log(authorized); // true
@francium-lupe
francium-lupe / repoadmins3.polar
Created January 17, 2024 22:38
(ReBAC) in Node.js 13
// Issue `tps-reports-99` belongs to repository `tps-reports`
await oso.tell(
'has_relation', // Fact type
{ type: 'Issue', id: 'tps-reports-99' }, // Resource
'repository', // Relation
{ type: 'Repository', id: 'tps-reports' } // Actor
);
// User `Bill` has role `admin` on repository `tps-reports`
await oso.tell(
@francium-lupe
francium-lupe / repoadmins2.polar
Created January 17, 2024 22:38
(ReBAC) in Node.js 12
resource Issue {
# Permissions
permissions = ["edit"];
# Roles
roles = ["editor"];
# UPDATED: added repository Relation
relations = { creator: User, repository: Repository };
@francium-lupe
francium-lupe / repoadmins1.polar
Created January 17, 2024 22:37
(ReBAC) in Node.js 11
resource Repository {
# UPDATED: added roles to Repository
roles = ["admin"];
}
@francium-lupe
francium-lupe / peter3.polar
Created January 17, 2024 22:24
(ReBAC) in Node.js 10
const authorized = await oso.authorize(
{ type: 'User', id: 'Peter' },
'edit',
{ type: 'Issue', id: 'tps-reports-99' }
);
console.log(authorized); // true
@francium-lupe
francium-lupe / peter2.polar
Created January 17, 2024 22:23
(ReBAC) in Node.js 9
await oso.tell(
'has_relation', // Fact type
{ type: 'Issue', id: 'tps-reports-99' }, // Resource
'creator', // Relation
{ type: 'User', id: 'Peter' } // Actor
);
@francium-lupe
francium-lupe / peter.polar
Created January 17, 2024 21:02
(ReBAC) in Node.js 8
const authorized = await oso.authorize(
{ type: 'User', id: 'Peter' },
'edit',
{ type: 'Issue', id: 'tps-reports-99' }
);
console.log(authorized); // false
@francium-lupe
francium-lupe / users_edit_issues.polar
Created January 17, 2024 21:01
(ReBAC) in Node.js 7
resource Issue {
# Permissions
permissions = ["edit"];
# Roles
roles = ["editor"];
# UPDATED: added relationships
relations = { creator: User };
@francium-lupe
francium-lupe / oso_tell.polar
Created January 17, 2024 21:00
(ReBAC) in Node.js 6
await oso.tell(
'has_role', // Fact type
{ type: 'User', id: 'Bill' }, // Actor
'editor', // Role
{ type: 'Issue', id: 'tps-reports-99' } // Resource
);
@francium-lupe
francium-lupe / authorize.polar
Created January 17, 2024 20:59
(ReBAC) in Node.js 5
const authorized = await oso.authorize(
{ type: 'User', id: 'Bill' },
'edit',
{ type: 'Issue', id: 'tps-reports-99' }
);
console.log(authorized); // false