Skip to content

Commit 094d91a

Browse files
authored
[MSGraph] Enable app roleassignment commands for Service Principal (#23732)
* add approle api in local yaml * add approle api in local yaml * customize New-AzAdServiceprincipalAppRoleAssignment * app role * Delete src/Resources/MSGraph.Autorest/test/Get-AzADServicePrincipalAppRoleAssignedTo.Tests.ps1 * Delete src/Resources/MSGraph.Autorest/test/Remove-AzADServicePrincipalAppRoleAssignedTo.Tests.ps1 * Delete src/Resources/MSGraph.Autorest/test/Update-AzADServicePrincipalAppRoleAssignedTo.Tests.ps1 * add examples * remove useless parameters * Update New-AzADServicePrincipalAppRoleAssignment.Tests.ps1 * update * Update Get-AzADApplication.ps1 * Update Get-AzADApplication.ps1 * change output ux, resolve comments
1 parent 0939e23 commit 094d91a

21 files changed

+1571
-3
lines changed

src/Resources/MSGraph.Autorest/Az.MSGraph.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
DotNetFrameworkVersion = '4.7.2'
1212
RequiredAssemblies = './bin/Az.MSGraph.private.dll'
1313
FormatsToProcess = './Az.MSGraph.format.ps1xml'
14-
FunctionsToExport = 'Add-AzADAppPermission', 'Add-AzADGroupMember', 'Get-AzADAppCredential', 'Get-AzADAppFederatedCredential', 'Get-AzADApplication', 'Get-AzADAppPermission', 'Get-AzADGroup', 'Get-AzADGroupMember', 'Get-AzADOrganization', 'Get-AzADServicePrincipal', 'Get-AzADSpCredential', 'Get-AzADUser', 'New-AzADAppCredential', 'New-AzADAppFederatedCredential', 'New-AzADApplication', 'New-AzADGroup', 'New-AzADServicePrincipal', 'New-AzADSpCredential', 'New-AzADUser', 'Remove-AzADAppCredential', 'Remove-AzADAppFederatedCredential', 'Remove-AzADApplication', 'Remove-AzADAppPermission', 'Remove-AzADGroup', 'Remove-AzADGroupMember', 'Remove-AzADServicePrincipal', 'Remove-AzADSpCredential', 'Remove-AzADUser', 'Update-AzADAppFederatedCredential', 'Update-AzADApplication', 'Update-AzADGroup', 'Update-AzADServicePrincipal', 'Update-AzADUser', '*'
14+
FunctionsToExport = 'Add-AzADAppPermission', 'Add-AzADGroupMember', 'Get-AzADAppCredential', 'Get-AzADAppFederatedCredential', 'Get-AzADApplication', 'Get-AzADAppPermission', 'Get-AzADGroup', 'Get-AzADGroupMember', 'Get-AzADGroupOwner', 'Get-AzADOrganization', 'Get-AzADServicePrincipal', 'Get-AzADServicePrincipalAppRoleAssignment', 'Get-AzADSpCredential', 'Get-AzADUser', 'New-AzADAppCredential', 'New-AzADAppFederatedCredential', 'New-AzADApplication', 'New-AzADGroup', 'New-AzADGroupOwner', 'New-AzADServicePrincipal', 'New-AzADServicePrincipalAppRoleAssignment', 'New-AzADSpCredential', 'New-AzADUser', 'Remove-AzADAppCredential', 'Remove-AzADAppFederatedCredential', 'Remove-AzADApplication', 'Remove-AzADAppPermission', 'Remove-AzADGroup', 'Remove-AzADGroupMember', 'Remove-AzADGroupOwner', 'Remove-AzADServicePrincipal', 'Remove-AzADServicePrincipalAppRoleAssignment', 'Remove-AzADSpCredential', 'Remove-AzADUser', 'Update-AzADAppFederatedCredential', 'Update-AzADApplication', 'Update-AzADGroup', 'Update-AzADServicePrincipal', 'Update-AzADServicePrincipalAppRoleAssignment', 'Update-AzADUser', '*'
1515
AliasesToExport = 'Get-AzADServicePrincipalCredential', 'New-AzADServicePrincipalCredential', 'Remove-AzADServicePrincipalCredential', 'Set-AzADApplication', 'Set-AzADServicePrincipal', 'Set-AzADUser', '*'
1616
PrivateData = @{
1717
PSData = @{

src/Resources/MSGraph.Autorest/README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ exclude-tableview-properties: []
7878

7979
inlining-threshold: 200
8080

81-
8281
directive:
8382
- no-inline:
8483
- MicrosoftGraphUser
@@ -196,6 +195,33 @@ directive:
196195
set:
197196
property-name: Items
198197

198+
- where:
199+
subject: serviceprincipalapproleassignment$
200+
verb: New
201+
hide: true
202+
203+
- where:
204+
subject: serviceprincipalapproleassignment$
205+
parameter-name: ^DeletedDateTime$
206+
hide: true
207+
208+
- where:
209+
verb: Update
210+
subject: serviceprincipalapproleassignment$
211+
parameter-name: ^PrincipalId$|^DisplayName$|^ResourceDisplayName$|^ResourceId$
212+
hide: true
213+
214+
- where:
215+
model-name: MicrosoftGraphAppRoleAssignment
216+
set:
217+
format-table:
218+
properties:
219+
- Id
220+
- AppRoleId
221+
- PrincipalDisplayName
222+
- PrincipalId
223+
- CreatedDateTime
224+
199225
- where:
200226
subject: application$|applicationpassword$|applicationkey$|serviceprincipal$|serviceprincipalpassword$|serviceprincipalkey$|groupmember$|user$|GroupGraphRefMember$|grouprefmember$
201227
hide: true
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
2+
# ----------------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# Code generated by Microsoft (R) AutoRest Code Generator.Changes may cause incorrect behavior and will be lost if the code
14+
# is regenerated.
15+
# ----------------------------------------------------------------------------------
16+
17+
<#
18+
.Synopsis
19+
Create new navigation property to appRoleAssignments for servicePrincipals
20+
.Description
21+
Create new navigation property to appRoleAssignments for servicePrincipals
22+
.Example
23+
{{ Add code here }}
24+
.Example
25+
{{ Add code here }}
26+
27+
.Inputs
28+
Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Models.ApiV10.IMicrosoftGraphAppRoleAssignment
29+
.Outputs
30+
Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Models.ApiV10.IMicrosoftGraphAppRoleAssignment
31+
.Notes
32+
COMPLEX PARAMETER PROPERTIES
33+
34+
To create the parameters described below, construct a hash table containing the appropriate properties. For information on hash tables, run Get-Help about_Hash_Tables.
35+
36+
BODY <IMicrosoftGraphAppRoleAssignment>: Represents an Azure Active Directory object. The directoryObject type is the base type for many other directory entity types.
37+
[(Any) <Object>]: This indicates any property can be added to this object.
38+
[DeletedDateTime <DateTime?>]:
39+
[DisplayName <String>]: The name displayed in directory
40+
[AppRoleId <String>]: The identifier (id) for the app role which is assigned to the principal. This app role must be exposed in the appRoles property on the resource application's service principal (resourceId). If the resource application has not declared any app roles, a default app role ID of 00000000-0000-0000-0000-000000000000 can be specified to signal that the principal is assigned to the resource app without any specific app roles. Required on create.
41+
[PrincipalId <String>]: The unique identifier (id) for the user, group or service principal being granted the app role. Required on create.
42+
[ResourceDisplayName <String>]: The display name of the resource app's service principal to which the assignment is made.
43+
[ResourceId <String>]: The unique identifier (id) for the resource service principal for which the assignment is made. Required on create. Supports $filter (eq only).
44+
.Link
45+
https://learn.microsoft.com/powershell/module/az.resources/new-azadserviceprincipalapproleassignment
46+
#>
47+
function New-AzADServicePrincipalAppRoleAssignment {
48+
[OutputType([Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Models.ApiV10.IMicrosoftGraphAppRoleAssignment])]
49+
[CmdletBinding(DefaultParameterSetName='ObjectIdWithResourceIdParameterSet', PositionalBinding=$false, SupportsShouldProcess, ConfirmImpact='Medium')]
50+
param(
51+
[Parameter(ParameterSetName = 'ObjectIdWithResourceIdParameterSet', Mandatory)]
52+
[Parameter(ParameterSetName = 'ObjectIdWithResourceDisplayNameParameterSet', Mandatory)]
53+
[Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Category('Path')]
54+
[System.String]
55+
# The unique identifier (id) for the user, group or service principal being granted the app role.
56+
# Required on create.
57+
${ServicePrincipalId},
58+
59+
[Parameter(ParameterSetName = 'SPNWithResourceIdParameterSet', Mandatory)]
60+
[Parameter(ParameterSetName = 'SPNWithResourceDisplayNameParameterSet', Mandatory)]
61+
[Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Category('Body')]
62+
[System.String]
63+
# The name displayed in directory
64+
${ServicePrincipalDisplayName},
65+
66+
[Parameter()] # ParameterSetName='CreateExpanded')]
67+
[Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Category('Body')]
68+
[System.Collections.Hashtable]
69+
# Additional Parameters
70+
${AdditionalProperties},
71+
72+
[Parameter()]
73+
[Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Category('Body')]
74+
[System.String]
75+
# The identifier (id) for the app role which is assigned to the principal.
76+
# This app role must be exposed in the appRoles property on the resource application's service principal (resourceId).
77+
# If the resource application has not declared any app roles, a default app role ID of 00000000-0000-0000-0000-000000000000 can be specified to signal that the principal is assigned to the resource app without any specific app roles.
78+
# Required on create.
79+
${AppRoleId},
80+
81+
[Parameter(DontShow)]
82+
[Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Category('Body')]
83+
[System.DateTime]
84+
# .
85+
${DeletedDateTime},
86+
87+
[Parameter(ParameterSetName = 'ObjectIdWithResourceIdParameterSet', Mandatory)]
88+
[Parameter(ParameterSetName = 'SPNWithResourceIdParameterSet', Mandatory)]
89+
[Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Category('Body')]
90+
[System.String]
91+
# The unique identifier (id) for the resource service principal for which the assignment is made.
92+
# Required on create.
93+
# Supports $filter (eq only).
94+
${ResourceId},
95+
96+
[Parameter(ParameterSetName = 'ObjectIdWithResourceDisplayNameParameterSet', Mandatory)]
97+
[Parameter(ParameterSetName = 'SPNWithResourceDisplayNameParameterSet', Mandatory)]
98+
[Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Category('Body')]
99+
[System.String]
100+
# The display name of the resource app's service principal to which the assignment is made.
101+
${ResourceDisplayName},
102+
103+
[Parameter()]
104+
[Alias('AzureRMContext', 'AzureCredential')]
105+
[ValidateNotNull()]
106+
[Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Category('Azure')]
107+
[System.Management.Automation.PSObject]
108+
# The credentials, account, tenant, and subscription used for communication with Azure.
109+
${DefaultProfile},
110+
111+
[Parameter(DontShow)]
112+
[Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Category('Runtime')]
113+
[System.Management.Automation.SwitchParameter]
114+
# Wait for .NET debugger to attach
115+
${Break},
116+
117+
[Parameter(DontShow)]
118+
[ValidateNotNull()]
119+
[Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Category('Runtime')]
120+
[Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Runtime.SendAsyncStep[]]
121+
# SendAsync Pipeline Steps to be appended to the front of the pipeline
122+
${HttpPipelineAppend},
123+
124+
[Parameter(DontShow)]
125+
[ValidateNotNull()]
126+
[Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Category('Runtime')]
127+
[Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Runtime.SendAsyncStep[]]
128+
# SendAsync Pipeline Steps to be prepended to the front of the pipeline
129+
${HttpPipelinePrepend},
130+
131+
[Parameter(DontShow)]
132+
[Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Category('Runtime')]
133+
[System.Uri]
134+
# The URI for the proxy server to use
135+
${Proxy},
136+
137+
[Parameter(DontShow)]
138+
[ValidateNotNull()]
139+
[Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Category('Runtime')]
140+
[System.Management.Automation.PSCredential]
141+
# Credentials for a proxy server to use for the remote call
142+
${ProxyCredential},
143+
144+
[Parameter(DontShow)]
145+
[Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Category('Runtime')]
146+
[System.Management.Automation.SwitchParameter]
147+
# Use the default credentials for the proxy
148+
${ProxyUseDefaultCredentials}
149+
)
150+
151+
process {
152+
switch ($PSCmdlet.ParameterSetName) {
153+
{($_ -eq 'SPNWithResourceIdParameterSet') -or ($_ -eq 'SPNWithResourceDisplayNameParameterSet')}{
154+
if ($PSBoundParameters['ServicePrincipalDisplayName']) {
155+
$PSBoundParameters['DisplayName'] = $PSBoundParameters['ServicePrincipalDisplayName']
156+
$null = $PSBoundParameters.Remove('ServicePrincipalDisplayName')
157+
158+
$sp = Get-AzADServicePrincipal -DisplayName $PSBoundParameters['DisplayName']
159+
if($null -eq $sp) {
160+
Write-Error "Cannot find service principal by DisplayName $($PSBoundParameters['DisplayName'])"
161+
}
162+
163+
$PSBoundParameters['ServicePrincipalId'] = $sp.Id
164+
}
165+
}
166+
167+
{($_ -eq 'SPNWithResourceDisplayNameParameterSet') -or ($_ -eq 'ObjectIdWithResourceDisplayNameParameterSet')} {
168+
if ($PSBoundParameters['ResourceDisplayName']) {
169+
$sp = Get-AzADServicePrincipal -DisplayName $PSBoundParameters['ResourceDisplayName']
170+
if($null -eq $sp) {
171+
Write-Error "Cannot find resource service principal by ResourceDisplayName $($PSBoundParameters['ResourceDisplayName'])"
172+
}
173+
174+
$PSBoundParameters['ResourceId'] = $sp.Id
175+
}
176+
}
177+
}
178+
179+
$PSBoundParameters['PrincipalId'] = $PSBoundParameters['ServicePrincipalId']
180+
181+
. Az.MSGraph.internal\New-AzADServicePrincipalAppRoleAssignment @PSBoundParameters
182+
}
183+
184+
}
185+

src/Resources/MSGraph.Autorest/docs/Az.MSGraph.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ Retrieve a list of organization objects.
5050
### [Get-AzADServicePrincipal](Get-AzADServicePrincipal.md)
5151
Lists entities from service principals or get entity from service principals by key
5252

53+
### [Get-AzADServicePrincipalAppRoleAssignment](Get-AzADServicePrincipalAppRoleAssignment.md)
54+
Get appRoleAssignments from servicePrincipals
55+
5356
### [Get-AzADSpCredential](Get-AzADSpCredential.md)
5457
Lists key credentials and password credentials for an service principal.
5558

@@ -74,6 +77,9 @@ Create new navigation property ref to owners for groups
7477
### [New-AzADServicePrincipal](New-AzADServicePrincipal.md)
7578
Adds new entity to servicePrincipals
7679

80+
### [New-AzADServicePrincipalAppRoleAssignment](New-AzADServicePrincipalAppRoleAssignment.md)
81+
Create new navigation property to appRoleAssignments for servicePrincipals
82+
7783
### [New-AzADSpCredential](New-AzADSpCredential.md)
7884
Creates key credentials or password credentials for an service principal.
7985

@@ -108,6 +114,9 @@ Delete ref of navigation property owners for groups
108114
### [Remove-AzADServicePrincipal](Remove-AzADServicePrincipal.md)
109115
Deletes entity from service principal.
110116

117+
### [Remove-AzADServicePrincipalAppRoleAssignment](Remove-AzADServicePrincipalAppRoleAssignment.md)
118+
Delete navigation property appRoleAssignments for servicePrincipals
119+
111120
### [Remove-AzADSpCredential](Remove-AzADSpCredential.md)
112121
Removes key credentials or password credentials for an service principal.
113122

@@ -126,6 +135,9 @@ Update entity in groups
126135
### [Update-AzADServicePrincipal](Update-AzADServicePrincipal.md)
127136
Updates entity in service principal
128137

138+
### [Update-AzADServicePrincipalAppRoleAssignment](Update-AzADServicePrincipalAppRoleAssignment.md)
139+
Update the navigation property appRoleAssignments in servicePrincipals
140+
129141
### [Update-AzADUser](Update-AzADUser.md)
130142
Updates entity in users
131143

0 commit comments

Comments
 (0)