Skip to content

Commit 7e106b3

Browse files
committed
Made updates to the article
1 parent 915a0d5 commit 7e106b3

File tree

1 file changed

+40
-11
lines changed

1 file changed

+40
-11
lines changed

microsoftgraph/docs-conceptual/tutorial-grant-delegated-api-permissions.md

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
---
2-
title: "Grant delegated permissions programmatically in Azure AD"
3-
description: "Learn how to grant delegated permissions programmatically in Azure AD using Microsoft Graph PowerShell"
2+
title: "Grant and revoke delegated permissions programmatically in Azure AD"
3+
description: "Learn how to grant and revoke delegated permissions programmatically in Azure AD using Microsoft Graph PowerShell"
44
ms.topic: tutorial
5-
ms.date: 12/07/2022
5+
ms.date: 03/13/2023
66
author: msewaweru
77
manager: CelesteDG
88
ms.author: eunicewaweru
99
ms.reviewer: jawoods, phsignor
1010
---
1111

12-
# Tutorial: Grant delegated permissions in Azure AD
12+
# Tutorial: Grant and revoke delegated permissions in Azure AD
1313

1414
When you grant API permissions to a client app in Azure AD, the permission grants are recorded as objects that can be accessed, updated, or deleted like other objects. Using Microsoft Graph PowerShell cmdlets to directly create permission grants is a programmatic alternative to [interactive consent](/azure/active-directory/manage-apps/consent-and-permissions-overview). This can be useful for automation scenarios, bulk management, or other custom operations in your organization.
1515

1616
>[!Caution]
1717
>Be Careful! Permissions created programmatically are not subject to review or confirmation. They take effect immediately.
1818
19-
In this tutorial, you'll grant delegated permissions that are exposed by an API to an app. Delegated permissions, also called scopes or OAuth2 permissions, allow an app to call an API on behalf of a signed-in user.
19+
In this tutorial, you'll grant and revoke delegated permissions that are exposed by an API to an app. Delegated permissions, also called scopes or OAuth2 permissions, allow an app to call an API on behalf of a signed-in user.
2020

2121
## Prerequisites
2222

@@ -35,7 +35,7 @@ To successfully complete this tutorial, make sure you have the required prerequi
3535
3636
## Step 1: Get the delegated permissions of the resource service principal
3737
38-
Before you can grant delegated permissions, you must first identify the delegated permissions to grant and the resource service principal that exposes the delegated permissions. Delegated permissions are defined in the `oauth2PermissionScopes` object of a service principal.
38+
Before you can grant delegated permissions, you must first identify the delegated permissions to grant and the resource service principal that exposes the delegated permissions. Delegated permissions are defined in the `oauth2PermissionScopes` object of a service principal.
3939
4040
In this article, you'll use the `Microsoft Graph` service principal in the tenant as your resource service principal.
4141
@@ -107,7 +107,7 @@ AppId : 05210c44-437f-4a40-bd38-b5b4eaf251ef
107107
SignInAudience : AzureADandPersonalMicrosoftAccount
108108
```
109109

110-
## Step 3: Grant delegated permission to the client service principal
110+
## Step 3: Grant delegated permissions to the client enterprise application
111111

112112
To create a delegated permission grant, you'll need the following information:
113113

@@ -139,10 +139,25 @@ PrincipalId :
139139
ResourceId : a67ad0d0-a7d1-4adb-8cd9-bcdd0c866d3c
140140
Scope : Group.Read.All
141141
```
142+
To confirm the delegated permissions assigned to the service principal on behalf of the user, you run the following command.
142143

143-
### Step 4: Assign more or revoke delegated permissions to the service principal
144+
```powershell
145+
Get-MgOauth2PermissionGrant -Filter "clientId eq '22c1770d-30df-49e7-a763-f39d2ef9b369' and consentType eq 'AllPrincipals'"
146+
```
147+
148+
```Output
149+
ClientId : 22c1770d-30df-49e7-a763-f39d2ef9b369
150+
ConsentType : AllPrincipals
151+
Id : DXfBIt8w50mnY_OdLvmzadDQeqbRp9tKjNm83QyGbTw
152+
PrincipalId :
153+
ResourceId : 2cab1707-656d-40cc-8522-3178a184e03d
154+
Scope : Group.Read.All,User.Read.All
155+
AdditionalProperties : {}
156+
```
157+
158+
### Step 4: Grant more delegated permissions to the enterprise application
144159

145-
You can add more or reduce scopes from an existing oauth2PermissionGrant object.
160+
You can add more permissions to an existing oauth2PermissionGrant object.
146161

147162
To add the `User.Read.All` scope to the oauthPermissionGrant object, run:
148163

@@ -154,10 +169,24 @@ $params = @{
154169
Update-MgOauth2PermissionGrant -OAuth2PermissionGrantId 'DXfBIt8w50mnY_OdLvmzadDQeqbRp9tKjNm83QyGbTw' -BodyParameter $params
155170
```
156171

157-
To revoke a delegated permission grant, run:
172+
### Step 5: Revoke delegated permissions granted to an enterprise application
173+
174+
If a service principal has been granted multiple delegated permission grants, you can choose to revok either specific gants or all grants.
175+
176+
- To revoke one or more grants, update oauthPermissionGrant object and specify only the delegated permissions to retain in the **scope** parameter. For example, to revoke the `User.read.All` permission, run:
177+
178+
```powershell
179+
$params = @{
180+
Scope = "Group.Read.All"
181+
}
182+
183+
Update-MgOauth2PermissionGrant -OAuth2PermissionGrantId 'DXfBIt8w50mnY_OdLvmzadDQeqbRp9tKjNm83QyGbTw' -BodyParameter $params
184+
```
185+
186+
- To revoke all grants, use `Remove-MgOauth2PermissionGrant`.
158187

159188
```powershell
160-
Remove-MgOauth2PermissionGrant -OAuth2PermissionGrantId 'DXfBIt8w50mnY_OdLvmzaQcXqyxtZcxAhSIxeKGE4D0'
189+
Remove-MgOauth2PermissionGrant -OAuth2PermissionGrantId 'DXfBIt8w50mnY_OdLvmzadDQeqbRp9tKjNm83QyGbTw'
161190
```
162191

163192
When a delegated permission grant is deleted, the access it granted is revoked. Existing access tokens will continue to be valid for their lifetime, but new access tokens will not be granted for the delegated permissions identified in the deleted oAuth2PermissionGrant.

0 commit comments

Comments
 (0)