The Roles and Permissions example below is a trip booking system that has owners and/or viewers, both of which can have more granular permissions like adding bookings to a trip or viewing a trip’s bookings.To represent this in an Auth0 FGA environment, you need to:
Understand how roles are related to direct relations for the trip booking system
Add implied relations to the existing authorization model to define permissions for bookings
Check user roles and their permissions based on relationship
tuples for direct and implied relations
Permissions are relations that users get through other relations. To avoid adding a direct relationship type restriction to the relation in the authorization model while representing permissions, they instead define the relation via other relations in the model, which indicates that it is a permission granted to and implied from a different relation.To add permissions related to bookings, add new relations to the trip object type denoting the various actions a user can take on trips, like view, edit, delete, or rename.To allow viewers of a trip to have permissions to view bookings and owners to have permissions to add/view bookings, you modify the type:
Note: both booking_viewer and booking_adder don’t have direct relationship type restrictions, which ensures that the relation can only be assigned through the role and not directly.
Your type definitions reflects the roles and permissions on how bookings can be viewed/added, so you can create relationship tuples to assign roles to users, then check if users have the proper permissions.Create two relationship tuples:
give bob the role of viewer on trip called Europe.
give alice the role of owner on trip called Europe.
Now check: is bob allowed to view bookings on trip Europe?bob is a booking_viewer because of the following chain of resolution:
bob is a viewer on trip: Europe
Any user related to the objecttrip:Europe as viewer is also related as a booking_viewer (i.e usersRelatedToObjectAs: viewer)
Therefore, all viewers on a given trip are booking_viewers
To confirm that bob is not allowed to add bookings on trip Europe, run the following check:You also check: is alice allowed to view and add bookings on trip Europe?alice is a booking_viewer and booking_adder because of the following chain of resolution:
alice is a owner on trip: Europe
Any user related to the objecttrip:Europe as owner is also related as a booking_viewer
Any user related to the objecttrip:Europe as owner is also related as a booking_adder
Therefore, all owners on a given trip are booking_viewers and booking_adders on that trip
Use unique ids for each object and user within your application domain when creating relationship tuples for Auth0 Fine-Grained Authorization (FGA). This example first names and simple ids as an easy-to-follow example.