How to add application role assignment to an EntraID enterprise application?

Marta Dubas 20 Reputation points
2024-10-03T15:21:34.1966667+00:00

I have an Enterprise application which was created from Spacelift (Cloud integration with Azure).

Spacelift request does not create App registration, only service principal (Enterprise application). I want this service principal to have permissions to create new app registrations and app role assignments. I understand the enterprise application needs to have permission Application.ReadWrite.All (1bfefb4e-e0b5-418b-a88f-73c46d2cc8e9) ref. https://docs.microsoft.com/en-us/graph/permissions-reference#all-permissions-and-ids, not delegated permission with the same name.

How can I add this permission to the enterprise application? I found this giude: https://learn.microsoft.com/en-us/graph/api/serviceprincipal-post-approleassignments?view=graph-rest-1.0&tabs=http but I do not understand what my resourceId should be. I want to run the command from powershell using Connect-MgGraph.

Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
22,058 questions
0 comments No comments
{count} votes

Accepted answer
  1. Andy David - MVP 149.1K Reputation points MVP
    2024-10-03T15:36:15.58+00:00

    $graphSPN = Get-MgServicePrincipal -Filter "AppId eq '00000003-0000-0000-c000-000000000000'"

    $permission = "Application.ReadWrite.All"

    $appRole = $graphSPN.AppRoles |

    Where-Object Value -eq $permission |
    
    Where-Object AllowedMemberTypes -contains "Application"
    

    Verify:

    $appRole

    $sp = Get-MgServicePrincipal -ServicePrincipalId <ID of App>

    $bodyParam = @{

    PrincipalId = $sp.Id
    
    ResourceId  = $graphSPN.Id
    
    AppRoleId   = $appRole.Id
    

    New-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $sp.Id -BodyParameter $bodyParam

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.