This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
authorized = await oso.authorize( | |
{ type: 'User', id: 'Bill' }, | |
'edit', | |
{ type: 'Issue', id: 'tps-reports-99' } | |
); | |
console.log(authorized); // true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource Issue { | |
# Permissions | |
permissions = ["edit"]; | |
# Roles | |
roles = ["editor"]; | |
# UPDATED: added repository Relation | |
relations = { creator: User, repository: Repository }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource Repository { | |
# UPDATED: added roles to Repository | |
roles = ["admin"]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const authorized = await oso.authorize( | |
{ type: 'User', id: 'Peter' }, | |
'edit', | |
{ type: 'Issue', id: 'tps-reports-99' } | |
); | |
console.log(authorized); // true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
await oso.tell( | |
'has_relation', // Fact type | |
{ type: 'Issue', id: 'tps-reports-99' }, // Resource | |
'creator', // Relation | |
{ type: 'User', id: 'Peter' } // Actor | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const authorized = await oso.authorize( | |
{ type: 'User', id: 'Peter' }, | |
'edit', | |
{ type: 'Issue', id: 'tps-reports-99' } | |
); | |
console.log(authorized); // false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource Issue { | |
# Permissions | |
permissions = ["edit"]; | |
# Roles | |
roles = ["editor"]; | |
# UPDATED: added relationships | |
relations = { creator: User }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
await oso.tell( | |
'has_role', // Fact type | |
{ type: 'User', id: 'Bill' }, // Actor | |
'editor', // Role | |
{ type: 'Issue', id: 'tps-reports-99' } // Resource | |
); |
NewerOlder