Access Restriction in a Canvas App Using a SharePoint Group and Power Automate


In this Power Apps Tutorial,

We will discuss how to restrict users from accessing certain features in a canvas app, while other users can still see and use features.

How to use SharePoint action in Power Automate to authenticate a user.

Why to Restrict Access?

In any App, there’s always more than one type of user. For example, there will be customers, staff, administrators, in business management application. An administrator will have access to everything meanwhile, staff will have limited access however a customer can only access his data.

Therefore, we need to make sure that we restrict users from interacting with specific data or features. For example, using Power Automate, we can hide anything in our Canvas App from users so that they do not interact with it. With the help of SharePoint group we will come to know how has access and who does not.

1.     Create a SharePoint group.

Navigate to SharePoint site click on setting and site permission.








Next click on Create Group










A New window will get open please Name and About Me Description, Owner, Group Settings, Give Group Permission to this Site.

After creating the group, add a user to it.

















2.     Create a Flow to Authenticate Users

Create an instant flow with PowerApps as a trigger and add three variables.

Email: This will be an input from the canvas app.

User Info – We’ll store user information that SharePoint API will fetch.

Should Access – This will initially be false.






















Now Add the 'Send HTTP Request to SharePoint' action.















Now let us add a condition where we will check if the result is empty or if it returns the information about a user.

In the 'value' property of the 'Condition,' add an expression. This expression will extract the length of the 'results' array from the http response.

Expression:

length(body('Send_an_HTTP_request_to_SharePoint')?['d']?['results'])

















If the length is 0, the user is not present in the SharePoint group. This is all we need to authenticate a user. Now, if you remember, we already initialized a 'ShouldAccess' variable as false. Therefore, we will only update this variable as true when the above condition is false, which means the 'results' array is not empty

So, in the 'No' section after the condition. Then, add the 'Set variable' action and update the 'ShouldAccess' variable as true. We are almost done but let us send the response to the canvas app using the 'Respond to PowerApps' action.


3.     Create a Canvas app.


















Hide Elements in the Canvas App Using Global Variables

Select your current screen -> Action -> Power Automate -> RestrictingAccess








































Now in the formula bar of 'On Visible' property, add this formula:

Set(CheckUser, RestrictingAccess.Run(User().Email));

Set(

    IsVisible,

    If(

        Lower(CheckUser.shouldaccess) = "true",

        true,

        false

    )

)
















Set(IsVisible) is another global variable we are using to check if the response is true or false. We will use this variable on Admin Button to hide it from staff.


















In some scenarios where you don’t want to hide the features entirely from the user but also want to restrict them from using them. In such a case, you can use the DisplayMode property of the admin icon.

If(IsVisible, DisplayMode.Edit, DisplayMode.Disabled)


















Let run the app and check the uses exist in this group while able to see the admin button is disabled.




Comments

Popular posts from this blog

How to implement approval in Teams using Adaptive Cards

Open canvas app with Customize the command bar using command designer

Create email templates in dynamic 365 and send email using Power Automate

HTTP Request Methods

Duplicate Detection in Dynamics 365 using power apps.