Azure

Removing user consent from an Azure AD application

1 min read

I’ve been working with my team on refactoring the authentication process that has been put in place in the application I am working on. One of the requirements was that we wanted to test out what happens when the user sees the user consentement (that is that the user consents the application to access data on its behalf), but also, when we do not see the user consentement.

To my demise, finding out what has been granted and what has not, is not user friendly in the Azure portal. For my own sake, and perhaps yours, I will try to demystify the where and the how.

Finding out the grants

To find out what API permissions have been accepted or granted by users, for your application, in the Azure portal, is not trivial to find. To do that, you need to go in the Azure Active Directory blade, and navigate to the Enterprise applications blade. Find your application and click on it. In your application, under the security section, click on the permissions blade. Within it, you should have the user consent tab. You can then see how many users (and who) have consented to your application.

Azure Ad Application user consent grants
Azure Ad Application user consent grants

Remove the grants

Removing the grants, for a specific user, specific users or all users, cannot be done through the portal. Currently there is no UI features to remove consented permissions, PowerShell or using the Graph API is the only way. As you can see in the above picture, there are ways to play with this. If you click on Review permissions, you will see that Microsoft gives you some pointers on what can be done through PowerShell depending on your scenario.

In my case, I wanted to remove 1 user (my user) from the granted consentement.

The following example is a PowerShell script that allows the removal of 1 user who’s consented that I’ve put together. You will need the AzureAD PowerShell module. Unfortunately, due to some problematic with .NET Core, the module doesn’t work well in PowerShell 6/7.

Usage:
Note: script the name of the file that you saved the script under

Script.ps1 -AzureAdServicePrincipalObjectId "1a358771-2075-4bed-9fc0-fa9d9bcfbc59" -UserPrincipalObjectId "9d34b730-ca10-45ff-9b4c-643ef17cee78" 

Hope this helps anyone who may be in the same boat.