Power Apps - Check Group Membership For Groups With > 1,000 Members
What
There are occasions when it is useful to check inside a Canvas App whether the logged-in user is a member of a specific Security Group.
This allows you to implement hide/show functionality for areas of the application that you may only want users/administrators to see.
Why
The standard method I've used in the past to implement this 'group membership' check is to call the following Connector/Function:
Using this connector, you would first get a list of All the members of a specific security group, then you would do a Filter on that collection to check if the logged in user is one of the Members.
So below we're going to show you how to do the same check by using MS Graph API calls that all users have access to.
How
- Get the ID of the Group you wish to confirm membership for
- Call the following Graph API to get a list of all Groups that the logged in user is a member of: https://graph.microsoft.com/v1.0/me/transitiveMemberOf/microsoft.graph.group
- Check if the ID from step 1 exists in the collection of ID's from Step 2
The Specific Scenario I was solving
The reason I required this recently, was due to a client that was using PAYG licensing to manage access to premium applications. The PAYG costs were getting out of control, they had spare licenses, but could not accurately determine who needed them until it was too late. Therefore we needed a user-friendly way to push staff through this app quickly if they had a license, and stop them if they did not.
We implemented a Timer OnStart to check the final variable, and based on that, launch the correct app (which was passed in as a parameter to the License Checker App.
Thank You
Thank you to Reza Dorrani for the tips on how to call Graph API directly within a PowerApp: https://www.youtube.com/watch?v=ZzWdXiMzA-c
Comments
Post a Comment