Skip to content

Commit b940020

Browse files
committed
Updates
1 parent 9b3b7b9 commit b940020

File tree

1 file changed

+39
-39
lines changed

1 file changed

+39
-39
lines changed

articles/active-directory/managed-identities-azure-resources/how-to-assign-app-role-managed-identity-powershell.md

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ ms.custom: devx-track-azurepowershell
2323
Managed identities for Azure resources provide Azure services with an identity in Azure Active Directory. They work without needing credentials in your code. Azure services use this identity to authenticate to services that support Azure AD authentication. Application roles provide a form of role-based access control, and allow a service to implement authorization rules.
2424

2525
> [!NOTE]
26-
> The tokens which your application receives are cached by the underlying infrastructure, which means that any changes to the managed identity's roles can take significant time to take effect. For more information, see [Limitation of using managed identities for authorization](managed-identity-best-practice-recommendations.md#limitation-of-using-managed-identities-for-authorization).
26+
> The tokens that your application receives are cached by the underlying infrastructure, which means that any changes to the managed identity's roles can take significant time to take effect. For more information, see [Limitation of using managed identities for authorization](managed-identity-best-practice-recommendations.md#limitation-of-using-managed-identities-for-authorization).
2727
2828
In this article, you learn how to assign a managed identity to an application role exposed by another application using Azure AD PowerShell.
2929

@@ -41,40 +41,40 @@ In this article, you learn how to assign a managed identity to an application ro
4141

4242
1. Find the object ID of the managed identity's service principal.
4343

44-
**For a system-assigned managed identity**, you can find the object ID on the Azure portal on the resource's **Identity** page. You can also use the following PowerShell script to find the object ID. You'll need the resource ID of the resource you created in step 1, which is available in the Azure portal on the resource's **Properties** page.
44+
**For a system-assigned managed identity**, you can find the object ID on the Azure portal on the resource's **Identity** page. You can also use the following PowerShell script to find the object ID. You'll need the resource ID of the resource you created in step 1, which is available in the Azure portal on the resource's **Properties** page.
4545

46-
```powershell
47-
$resourceIdWithManagedIdentity = '/subscriptions/{my subscription ID}/resourceGroups/{my resource group name}/providers/Microsoft.Compute/virtualMachines/{my virtual machine name}'
48-
(Get-AzResource -ResourceId $resourceIdWithManagedIdentity).Identity.PrincipalId
49-
```
46+
```powershell
47+
$resourceIdWithManagedIdentity = '/subscriptions/{my subscription ID}/resourceGroups/{my resource group name}/providers/Microsoft.Compute/virtualMachines/{my virtual machine name}'
48+
(Get-AzResource -ResourceId $resourceIdWithManagedIdentity).Identity.PrincipalId
49+
```
5050
51-
**For a user-assigned managed identity**, you can find the managed identity's object ID on the Azure portal on the resource's **Overview** page. You can also use the following PowerShell script to find the object ID. You'll need the resource ID of the user-assigned managed identity.
51+
**For a user-assigned managed identity**, you can find the managed identity's object ID on the Azure portal on the resource's **Overview** page. You can also use the following PowerShell script to find the object ID. You'll need the resource ID of the user-assigned managed identity.
5252
53-
```powershell
54-
$userManagedIdentityResourceId = '/subscriptions/{my subscription ID}/resourceGroups/{my resource group name}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{my managed identity name}'
55-
(Get-AzResource -ResourceId $userManagedIdentityResourceId).Properties.PrincipalId
56-
```
53+
```powershell
54+
$userManagedIdentityResourceId = '/subscriptions/{my subscription ID}/resourceGroups/{my resource group name}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{my managed identity name}'
55+
(Get-AzResource -ResourceId $userManagedIdentityResourceId).Properties.PrincipalId
56+
```
5757
5858
1. Create a new application registration to represent the service that your managed identity will send a request to. If the API or service that exposes the app role grant to the managed identity already has a service principal in your Azure AD tenant, skip this step. For example, if you want to grant the managed identity access to the Microsoft Graph API, you can skip this step.
5959
6060
1. Find the object ID of the service application's service principal. You can find this using the Azure portal. Go to Azure Active Directory and open the **Enterprise applications** page, then find the application and look for the **Object ID**. You can also find the service principal's object ID by its display name using the following PowerShell script:
6161
62-
# [Azure PowerShell](#tab/azurepowershell)
62+
# [Azure PowerShell](#tab/azurepowershell)
6363
64-
```powershell
65-
$serverServicePrincipalObjectId = (Get-AzureADServicePrincipal -Filter "DisplayName eq '$applicationName'").ObjectId
66-
```
64+
```powershell
65+
$serverServicePrincipalObjectId = (Get-AzureADServicePrincipal -Filter "DisplayName eq '$applicationName'").ObjectId
66+
```
6767
68-
# [Microsoft Graph](#tab/microsoftgraph)
68+
# [Microsoft Graph](#tab/microsoftgraph)
6969
70-
```powershell
71-
$serverServicePrincipalObjectId = (Get-MgServicePrincipal -Filter "DisplayName eq '$applicationName'").Id
72-
```
70+
```powershell
71+
$serverServicePrincipalObjectId = (Get-MgServicePrincipal -Filter "DisplayName eq '$applicationName'").Id
72+
```
7373
74-
---
74+
---
7575
76-
> [!NOTE]
77-
> Display names for applications are not unique, so you should verify that you obtain the correct application's service principal.
76+
> [!NOTE]
77+
> Display names for applications are not unique, so you should verify that you obtain the correct application's service principal.
7878
7979
1. Add an [app role](../develop/howto-add-app-roles-in-azure-ad-apps.md) to the application you created in step 3. You can create the role using the Azure portal or by using Microsoft Graph. For example, you could add an app role like this:
8080
@@ -98,27 +98,27 @@ In this article, you learn how to assign a managed identity to an application ro
9898
9999
Execute the following PowerShell command to add the role assignment:
100100
101-
# [Azure PowerShell](#tab/azurepowershell)
101+
# [Azure PowerShell](#tab/azurepowershell)
102102
103-
```powershell
104-
New-AzureADServiceAppRoleAssignment `
105-
-ObjectId $managedIdentityObjectId `
106-
-Id $appRoleId `
107-
-PrincipalId $managedIdentityObjectId `
108-
-ResourceId $serverServicePrincipalObjectId
109-
```
103+
```powershell
104+
New-AzureADServiceAppRoleAssignment `
105+
-ObjectId $managedIdentityObjectId `
106+
-Id $appRoleId `
107+
-PrincipalId $managedIdentityObjectId `
108+
-ResourceId $serverServicePrincipalObjectId
109+
```
110110
111-
# [Microsoft Graph](#tab/microsoftgraph)
111+
# [Microsoft Graph](#tab/microsoftgraph)
112112
113-
```powershell
114-
New-MgServicePrincipalAppRoleAssignment `
115-
-ServicePrincipalId $managedIdentityObjectId `
116-
-PrincipalId $managedIdentityObjectId `
117-
-ResourceId $serverServicePrincipalObjectId `
118-
-AppRoleId $appRoleId
119-
```
113+
```powershell
114+
New-MgServicePrincipalAppRoleAssignment `
115+
-ServicePrincipalId $managedIdentityObjectId `
116+
-PrincipalId $managedIdentityObjectId `
117+
-ResourceId $serverServicePrincipalObjectId `
118+
-AppRoleId $appRoleId
119+
```
120120
121-
---
121+
---
122122
123123
## Complete script
124124

0 commit comments

Comments
 (0)