<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sagar Singh</title>
    <description>The latest articles on DEV Community by Sagar Singh (@sagar-singh).</description>
    <link>https://dev.to/sagar-singh</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1133536%2Fe84d89b3-fb15-4922-b470-053889a8114d.jpeg</url>
      <title>DEV Community: Sagar Singh</title>
      <link>https://dev.to/sagar-singh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sagar-singh"/>
    <language>en</language>
    <item>
      <title>How I implemented Access Approval to Our Open Source Project</title>
      <dc:creator>Sagar Singh</dc:creator>
      <pubDate>Tue, 23 Jul 2024 15:30:00 +0000</pubDate>
      <link>https://dev.to/sagar-singh/how-i-implemented-access-approval-to-our-open-source-project-1c6n</link>
      <guid>https://dev.to/sagar-singh/how-i-implemented-access-approval-to-our-open-source-project-1c6n</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;A few days ago, some of my colleagues approached me regarding an issue with an Open Source application called &lt;a href="https://makaut-buddy.vercel.app/" rel="noopener noreferrer"&gt;Makaut Buddy&lt;/a&gt; which is a notes-sharing platform designed for our university, aimed at helping students share top notes, past exam questions, and YouTube tutorials efficiently.&lt;/p&gt;

&lt;p&gt;While they had successfully developed a system for uploading resources, they encountered a challenge in ensuring that only authorized individuals could upload content. &lt;/p&gt;

&lt;p&gt;As you can see in the demo, any user could create a resource after they sign up.This poses a big problem because we cannot regulate what users can upload, some might even upload harmful or disturbing content.&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/NVyf_wb-WPE"&gt;
&lt;/iframe&gt;
&lt;br&gt;
Initially, they defined an Admin role and granted a select group of individuals administrative privileges. However, as the number of roles increased, the code became increasingly complex and difficult to manage.&lt;/p&gt;

&lt;p&gt;This is when I had the idea to write this article to raise awareness about efficient ways of managing authorization using a Role-Based Access Control (RBAC) model with the help of third-party authorization tools like &lt;a href="https://permit.io/" rel="noopener noreferrer"&gt;Permit.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In addition to implementing RBAC, we also introduced a Request Access Approval system. This system ensures that any user who wants to upload content must first request access, which an admin can then approve or deny. This added layer of security helps us maintain the integrity of the content on Makaut Buddy.&lt;/p&gt;

&lt;p&gt;In this article, I have used JavaScript as the programming language and Next.js as the framework. However, the concepts discussed here are not language-specific, and you can implement them in your preferred programming language.&lt;/p&gt;

&lt;p&gt;By the end of this article, you will have the knowledge to implement a basic RBAC model in your application.&lt;/p&gt;

&lt;p&gt;With that said, let’s dive in!&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;What is Authorization ?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Remember those mornings rushing to school? The security guard checking your ID is a perfect example of authentication. They're verifying your identity as a student allowed on campus.&lt;/p&gt;

&lt;p&gt;But that's just the first step. Even after being identified, you wouldn't just walk into any classroom, right? That's where authorization comes in.&lt;/p&gt;

&lt;p&gt;Think of your class schedule as your authorization. It grants you access to specific areas (classrooms) based on your role (student enrolled in that class). You wouldn't be authorized to enter the teacher's lounge or the library's restricted section – even though you're a student (authenticated&lt;/p&gt;

&lt;p&gt;The difference between Authentication and Authorization is like asking “Who are you?” vs “What are you allowed to do?”&lt;/p&gt;

&lt;p&gt;Now let’s understand&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Why do we need an RBAC model for authorization 🤔?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Authorization is important in every organization as it prevents people from doing anything that they are not supposed to do , which ensures the safety of the organization and prevents the companies from making a loss .&lt;/p&gt;

&lt;p&gt;Let’s understand the above statement with an example.&lt;/p&gt;

&lt;p&gt;In a company there are senior engineers who are experienced and there are interns who are still learning. You can imagine the disaster it would cause if both the senior engineer and the intern have the same level of permissions. The interns who are still learning might unknowingly make some mistake for which the company will have to pay. In situations like these the Role Based Access Control Model works the best because the permissions are not assigned to individuals instead the permissions are assigned to roles like only a senior engineer or tech lead can Delete Resources whereas all interns can only view and manage resources.&lt;/p&gt;

&lt;p&gt;Next let’s see how we can implement RBAC in an application.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;How to implement RBAC in an app :&lt;/strong&gt;
&lt;/h2&gt;
&lt;h3&gt;
  
  
  1. &lt;strong&gt;Define Roles and Permissions&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;First, we need to define roles and assign permissions to each role.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: A Role is the position or purpose that someone has in a organization , we need roles so that we can differentiate between individuals based on the permissions or privileged assigned to that role.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;2. Assign Roles to Users&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;We need a way to assign a role to each user of the application. This is generally done after the user signs up.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;3. Create an Authorization API&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;We need an API in our backend that takes in the operation a user wants to perform and checks the user's authorization. The diagram below will give you a better understanding:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo84zcr9pq4u9mmim26zm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo84zcr9pq4u9mmim26zm.png" alt="create an authorization api" width="800" height="227"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, we are not going to implement the entire model from scratch. Instead, we are going to use a third party authorization tool called &lt;a href="https://permit.io/" rel="noopener noreferrer"&gt;Permit&lt;/a&gt; which will make the whole process of establishing authorization very smooth and efficient for us, so that you can work on the features that really matter.&lt;/p&gt;

&lt;p&gt;The below diagram shows you how we are going to leverage &lt;a href="https://permit.io/" rel="noopener noreferrer"&gt;Permit&lt;/a&gt; to implement RBAC in our applications :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fts59jxxswep9757s6oh2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fts59jxxswep9757s6oh2.png" alt="The below diagram shows you how we are going to leverage [Permit](https://permit.io/) to implement RBAC in our applications" width="800" height="390"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Implementing RBAC model :&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In this section, we will walk through the steps to implement Role-Based Access Control (RBAC) using &lt;a href="https://permit.io/" rel="noopener noreferrer"&gt;Permit&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbpxiytxzsq639rmufxyn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbpxiytxzsq639rmufxyn.png" alt="Implementing RBAC model" width="800" height="407"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 1: Create a Permit Account and Workspace
&lt;/h3&gt;

&lt;p&gt;As we are using &lt;a href="https://permit.io/" rel="noopener noreferrer"&gt;Permit&lt;/a&gt; for establishing an RBAC model , first we need to create a Permit account and a workspace :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flsy6aome5a9kzr33ylqx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flsy6aome5a9kzr33ylqx.png" alt="Create a Permit Account and Workspace" width="800" height="526"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 2: Create a Resource
&lt;/h3&gt;

&lt;p&gt;Now we need to create a Resource which is the entity we want to control access to in our application.&lt;/p&gt;

&lt;p&gt;For example, in a notes-taking application, the resource would be Notes, and the actions could be &lt;strong&gt;Create&lt;/strong&gt;, &lt;strong&gt;Read,&lt;/strong&gt; &lt;strong&gt;Update&lt;/strong&gt;, and &lt;strong&gt;Delete.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To create a resource:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go to the Policy section.&lt;/li&gt;
&lt;li&gt;Navigate to the Resources tab.&lt;/li&gt;
&lt;li&gt;Create a new resource by filling in the required details.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgq958mvkpehon0h5eowi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgq958mvkpehon0h5eowi.png" alt="Create a Resource" width="800" height="451"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the example above , the Resource name is Notes and the actions that the user is allowed to perform are Create, Read, Update and Delete.&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 3: Define Roles
&lt;/h3&gt;

&lt;p&gt;After creating the Resource ,we have to define the roles that are going to exist in our application :&lt;/p&gt;

&lt;p&gt;In this case, as the application is a notes sharing application for a university , the roles are going to be :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Admin : Who can create and read resources.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Student : Who can read resources.&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1nj6841pu4t8vvt0gt7n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1nj6841pu4t8vvt0gt7n.png" alt="Define Roles" width="800" height="467"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faczbr5etigexj5fxet19.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faczbr5etigexj5fxet19.png" alt="Define Roles 2" width="800" height="467"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 4: Assign Actions to Roles
&lt;/h3&gt;

&lt;p&gt;Once we have created both the roles, we now have to assign the actions that each role can perform from our policy editor, as shown below :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkv1jq5ty4krx9ek5ixv9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkv1jq5ty4krx9ek5ixv9.png" alt="Assign Actions to Roles" width="800" height="1547"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 5: Configure Backend APIs
&lt;/h3&gt;

&lt;p&gt;Now that your &lt;a href="https://permit.io/" rel="noopener noreferrer"&gt;Permit&lt;/a&gt; account is configured, you can start creating the backend APIs to communicate with Permit. We will use the Node.js SDK provided by Permit. You can find the SDK for your preferred programming language in the Permit Documentation .&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sync Users and Assign Default Role:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;First we need to make sure that each user that sign’s up in our application is synced to &lt;a href="https://permit.io/" rel="noopener noreferrer"&gt;permit&lt;/a&gt; directory and assigned a default role of Student.&lt;/p&gt;

&lt;p&gt;To do this we need to create a backend API as shown below :&lt;/p&gt;

&lt;p&gt;This API does 2 things :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Initializes the &lt;a href="https://permit.io/" rel="noopener noreferrer"&gt;Permit&lt;/a&gt; API.&lt;/li&gt;
&lt;li&gt;Creates a new user using the &lt;code&gt;createUser&lt;/code&gt; API.&lt;/li&gt;
&lt;li&gt;Assigns a default role using the &lt;code&gt;assignRole&lt;/code&gt; API.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6rkkcswp6jwgestec67f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6rkkcswp6jwgestec67f.png" alt="Initializes the Permit API" width="800" height="238"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpuwvnnoze7cm6zug1rfq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpuwvnnoze7cm6zug1rfq.png" alt="Configure Backend APIs" width="800" height="838"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can read more about all the APIs that permit provides at &lt;a href="https://docs.permit.io/" rel="noopener noreferrer"&gt;permit docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Get User Role&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Next, we need to create a backend API that gets the role of the user from &lt;a href="https://permit.io/" rel="noopener noreferrer"&gt;Permit.io&lt;/a&gt; and sends it back to the frontend .&lt;/p&gt;

&lt;p&gt;The API show below gets the user using the &lt;strong&gt;&lt;code&gt;permit.api.users.get(user_key)&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsfg9m8t8s8x2vps7weld.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsfg9m8t8s8x2vps7weld.png" alt="Get User Role" width="800" height="735"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This API gets the user role with which we can manipulate our front-end components to allow only the people having special roles to be able to see it.&lt;/p&gt;

&lt;p&gt;You can also check out the &lt;a href="https://docs.permit.io/how-to/enforce-permissions/check/" rel="noopener noreferrer"&gt;permit.check()&lt;/a&gt; function to verify if a user with a certain role is permitted to perform an operation.&lt;/p&gt;

&lt;p&gt;With this, we have successfully implemented an RBAC model using &lt;a href="https://permit.io" rel="noopener noreferrer"&gt;Permit&lt;/a&gt;. Now, we can integrate the backend routes with the frontend framework or library of your choice to complete the setup.&lt;/p&gt;
&lt;h2&gt;
  
  
  Implementing &lt;strong&gt;Access Approval System:&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;To complete our setup, we need a component that allows users to request role upgrades:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A normal user without admin privileges can view the permit element and request admin privileges.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhu1zz4a44w532le5oqu9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhu1zz4a44w532le5oqu9.png" alt="Access Approval System" width="800" height="416"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An admin user can approve or deny incoming requests for role upgrades from other users.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw87b69vb7qd05ha7v3hx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw87b69vb7qd05ha7v3hx.png" alt="Access Approval System" width="800" height="325"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 1: Create a Permit Element
&lt;/h3&gt;

&lt;p&gt;Permit Elements are a part of “&lt;a href="https://www.producthunt.com/posts/permit-share-if" rel="noopener noreferrer"&gt;Permit Share-If&lt;/a&gt;” which is a suite of prebuilt, embeddable UI components that make access sharing in applications a breeze. Designed to provide fully functional access control, they make delegating permission management to your users simple and safe.&lt;/p&gt;

&lt;p&gt;To implement this, first we need to create a permit element&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to the Elements tab in the Permit Dashboard.&lt;/li&gt;
&lt;li&gt;Click on Create Element under the User Management section.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4h87ujkhbpmx72owanqk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4h87ujkhbpmx72owanqk.png" alt="Access Approval System" width="800" height="397"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Then we have to fill the form with required information as shown below

&lt;ul&gt;
&lt;li&gt;Make the Admin role the workspace owner.&lt;/li&gt;
&lt;li&gt;Assign the Student role to the viewer section.&lt;/li&gt;
&lt;li&gt;Set the default role as Student.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft0gx5jnpvkfas3bfqdp6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft0gx5jnpvkfas3bfqdp6.png" alt="Access Approval System" width="800" height="414"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Save the element and create a new element under Access Request.:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F51udjvd4rxn8d79k275x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F51udjvd4rxn8d79k275x.png" alt="Access Approval System" width="800" height="326"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Then fill in the Information for Access Request

&lt;ul&gt;
&lt;li&gt;Select the User Management Element to connect your access-request element.&lt;/li&gt;
&lt;li&gt;Click on Create to finalize the element.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fanix2ijpm83q5ugf3j7q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fanix2ijpm83q5ugf3j7q.png" alt="Access Approval System" width="800" height="410"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Next, we’ll edit User Management Element

&lt;ul&gt;
&lt;li&gt;Go back to the User Management Element and edit it.&lt;/li&gt;
&lt;li&gt;Select the access-request element as the approval component in user management.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsegt8fskl5jax7l9fsvd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsegt8fskl5jax7l9fsvd.png" alt="Access Approval System" width="800" height="728"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That’s it we’ve created the elements.&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 2: Create Backend API for User Login
&lt;/h3&gt;

&lt;p&gt;Before using the elements, we need to create a backend api  for logging in the user to the permit element,&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: It's important to log in the user as early as possible, preferably right after signup.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now,  let’s look at the code :&lt;/p&gt;

&lt;p&gt;API code serving at endpoint  &lt;code&gt;/api/v1/login_permit/?userkey=user_key&lt;/code&gt; :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsn4t0obhtxabp6ukalyw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsn4t0obhtxabp6ukalyw.png" alt="Create Backend API for User Login" width="800" height="227"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 3: Frontend Code for Implementing Login
&lt;/h3&gt;

&lt;p&gt;The frontend code for implementing login  will look like this :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6wvpbmq58uz1lprevopu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6wvpbmq58uz1lprevopu.png" alt="Frontend Code for Implementing Login" width="800" height="76"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkaa25d4t0sns22xvis10.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkaa25d4t0sns22xvis10.png" alt="Frontend Code for Implementing Login" width="800" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That’s it we’ve set up our code.&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 4: Integrate Iframes into Frontend
&lt;/h3&gt;

&lt;p&gt;Now we just need to go over to the permit dashboard and copy both the user management iframe and access-request iframe like shown below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl2ajhnazniq11o3xlk87.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl2ajhnazniq11o3xlk87.png" alt="Frontend Code for Implementing Login" width="800" height="462"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3jbc1qz1li57ty7p5atv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3jbc1qz1li57ty7p5atv.png" alt="Frontend Code for Implementing Login" width="800" height="461"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now once we’ve got the code , we need to add the &lt;code&gt;iframe&lt;/code&gt; to our frontend where we want to show the elements to our users, we need to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Show the user management element to users with the admin role.&lt;/li&gt;
&lt;li&gt;Show the access request element to users with the student role.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With this, we have successfully set up an access approval system where users can request role upgrades, and admins can approve or deny these requests.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Demo of RBAC in a notes sharing application :&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Demo: Admin Access to Upload Widget:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This demo shows how a user with the "Admin" role can access the upload widget&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/xWQDI5N2TdM"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Demo: Student Role Restrictions and Access Request&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This demo illustrates how a user with the "Student" role cannot see the upload widget and can request an upgrade to the "Admin" role :&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/Es69s8qiEog"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Demo: Approving Role Upgradation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This demo shows how privileged users can approve role upgrade requests:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/sz8TaNk9OZE"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Demo: Upgraded Role Access to Upload Widget&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This demo demonstrates how a user, after being upgraded from "Student" to "Admin," gains access to the upload widget&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/l5YaWi88n0o"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Conclusion :&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;That’s it , Thank you for reading this far .&lt;/p&gt;

&lt;p&gt;In this tutorial, we explored authorization and understood why authorization is very important in any application. We also looked at how we can set up and configure Permit to secure the application and control user access based on their roles .&lt;/p&gt;

&lt;p&gt;This article is just the tip of the iceberg of authorization and the RBAC model. You can look into ABAC and ReBAC for more fine grained Authorization.&lt;/p&gt;

&lt;p&gt;Permit Share-if has been launched recently on product hunt ,you can show some support here &lt;/p&gt;
&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
      &lt;div class="c-embed__cover"&gt;
        &lt;a href="https://www.producthunt.com/posts/permit-share-if" class="c-link s:max-w-50 align-middle" rel="noopener noreferrer"&gt;
          &lt;img alt="" src="https://res.cloudinary.com/practicaldev/image/fetch/s--z9pVIgBM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ph-files.imgix.net/1fa73cf8-5d70-406e-9562-92cb5ce478e1.png%3Fauto%3Dformat%26fit%3Dcrop%26frame%3D1%26h%3D512%26w%3D1024" height="400" class="m-0" width="800"&gt;
        &lt;/a&gt;
      &lt;/div&gt;
    &lt;div class="c-embed__body"&gt;
      &lt;h2 class="fs-xl lh-tight"&gt;
        &lt;a href="https://www.producthunt.com/posts/permit-share-if" rel="noopener noreferrer" class="c-link"&gt;
           Permit Share-If - Embeddable access sharing components | Product Hunt
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;p class="truncate-at-3"&gt;
          “Permit Share-If” is a suite of prebuilt, embeddable UI components that make access sharing in applications a breeze. Designed to provide fully functional access control, they make delegating permission management to your users simple and safe.
        &lt;/p&gt;
      &lt;div class="color-secondary fs-s flex items-center"&gt;
          &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://res.cloudinary.com/practicaldev/image/fetch/s--cmeqGyAO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://ph-static.imgix.net/ph-favicon-coral.ico" width="240" height="240"&gt;
        producthunt.com
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;


</description>
      <category>nextjs</category>
      <category>webdev</category>
      <category>opensource</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
