Why New-MgServicePrincipalAppRoleAssignment has two very similar parameters ServicePrincipalId and PrincipalId?

Vadim Bondaruk 41 Reputation points
2023-12-20T09:13:29.13+00:00

I am investigating Microsoft Graph powershell module and encountered New-MgServicePrincipalAppRoleAssignment method. There are two very similar parameters ServicePrincipalId and PrincipalId. All examples that i found use the same value for both parameters. I can not figure out when these params will have different values, maybe someone could help with it?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
13,593 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,943 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
24,595 questions
0 comments No comments
{count} votes

Accepted answer
  1. Carlos Solís Salazar 18,191 Reputation points MVP Moderator
    2023-12-21T00:33:52.71+00:00

    The New-MgServicePrincipalAppRoleAssignment method in the Microsoft Graph PowerShell module is used to assign an application role to a service principal. The confusion around ServicePrincipalId and PrincipalId parameters is understandable, as their roles are closely related but distinct.

    Here's a breakdown of these parameters:

    ServicePrincipalId:

    • This is the ID of the service principal that represents the application to which you are assigning the role. Essentially, this is the "target" application that has defined the app roles.
    • In Azure AD, every application registered in the directory has an associated service principal, which is its identity for use in specific instances, like within your tenant.

    PrincipalId:

    • This refers to the object ID of the principal (which can be a user, group, or another service principal) to whom you are assigning the app role.
    • This parameter specifies "who" is receiving the role assignment.

    In many examples, you might see the same value used for both ServicePrincipalId and PrincipalId. This typically happens in scenarios where an application (service principal) is being granted a role within itself. For instance, this is common in scenarios where an application needs to access its own API.

    However, in a more general use case, these IDs would differ. For example, if you have Application A and you want to assign a role in Application A to a user or another application (Application B), then:

    • ServicePrincipalId would be the ID of Application A.
    • PrincipalId would be the ID of the user or Application B's service principal.

    This distinction allows for flexible role assignments, enabling various scenarios like granting one application permissions to another, or assigning specific roles to users or groups within an application.

    If this information was helpful or if you have any more questions, please let me know. Your feedback is valuable in ensuring you get the best possible assistance.

    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.