End to End Example
In this tutorial, we’ll walk you through how to build a comprehensive end-to-end authorization system using Permify Cloud. We’ll dive into example use cases, explore key concepts of Permify, and integrate sample codes from Permify’s SDKs to get you up and running quickly.
This guide consist of 4 main sections:
- Set Up Your First Project & Integrate With Your App
- Model Authorization Policy
- Add Permissions & Store Authorization Data
- Perform Access Check
By the end of this guide, you’ll be able to:
- Set up and configure Permify Cloud for your application.
- Build and test a secure authorization flow to control access across different parts of your app.
Let’s get started!
Setting Up Your First Project
To get started with building your authorization system, the first step is to sign up for a Permify Cloud account.
- Navigate to the Permify Cloud.
- Enter your details and create your account.
- After signing up, it will redirect you to the Organization Creation step.
- After creating the organization, you can invite your organization members.
Once your organization is created, Permify will automatically spin up a Starter project to set up your first authorization system.
It can take a couple of minutes to boot up the Starter project. Sometimes, refreshing the page might be required to see the active state.
Click the starter project to see the dashboard. You’re now ready to start defining your authorization rules and policies!
Integrating With Your Application
Now that your project is set up, it’s time to integrate Permify Cloud with your application using the appropriate client library.
Setup your client
Permify Cloud currently gives you an Endpoint and an API Key to connect via gRPC or REST connection. Here is where ou can find your Permify Host and API Key from project page as in the figure below:
By using these configuration you can set up clients via our SDKs.
Let’s try validating our connection by sending a List Tenants API request.
Here is an example Python List Tenant request that shows a successful List Tenants response.
Lets move forward with defining our authorization model into Permify Cloud!
Model Authorization Policy
In Permify, you can define that a user has certain permissions because of their relation to other entities.
An example of this would be granting a manager the same permissions as their subordinates, or giving a user access to a resource because they belong to a certain group.
This is facilitated by our relationship-based access control, which allows the definition of complex permission structures based on the relationships between users, roles, and resources.
What You Will Be Building
In this tutorial, we will build a sample application using Permify’s default example. Here is the schema that defines the relationships and permissions for our application:
Let’s dive into more details to understand our model:
Entities
Entity is an object that defines your resources that held role in your permission system. Our application will manage three main entities: User, Organization, and Repository.
Relations
Relations represent relationships between entities. Our application will have relations between users, organizations and repositories as follow:
- The relationship between a user and an organization involves the user potentially being either a member or an admin of the organization.
- The relationship between a repository and an organization is such that a repository belongs to an organization.
- The relationship between a repository and an user is such that a repository is created by a user.
Permissions
Permissions define what entities can perform within the system. Our application will manage permissions in relation to users, organizations, and repositories as follows:
- If a user is an admin of an organization, that user can edit all repositories within that organization.
- If a user is the owner of a repository, that user can edit the corresponding repository.
- If a user is the owner of a repository, that user can delete the corresponding repository.
To see a live example and test of this example schema, visit the Permify Playground.
Apply Model via SDK
Let’s insert the example schema into Permify using the Write Schema API
Here you can observe your configured and deployed schema history in the Schema Section.
We defined our model to Permify Cloud, lets add some permissions and send example API check request in our application.
Add Permissions & Store Authorization Data
Permify unifies your authorization data and the authorization schemas you have in a database of your preference, which serves as the single source of truth for all authorization queries and requests via the Permify API.
In Permify, you can store authorization data in two different forms: as relationships and as attributes.
For the sake of simplicity, we will only add relationships in this tutorial. Hence, same write API also applies for inserting attributes too.
For more information about adding permissions and storing data refer to Storing Data section.
Relationships
In Permify, relationship between your entities, objects, and users builds up a collection of access control lists (ACLs). Here is how we insert relationships into Permify via our SDKs using the Data Write API
We will assign admin role to the user:1 in organization:1 —> organization:1@admin#user:1
On Data Section, you will see the data you have inserted to Permify:
Perform Access Check
Access Check
Verify whether a specific subject has access to a given entity. This allows you to determine permissions such as whether a user can view, edit, or delete a particular resource.
Below is an example of an implemented Python access check request and response