You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add support for an Overwrite flag and logic to find & reuse existing templates/permission sets when creating app approval templates. Improve delegated permission handling by grouping multi-scope grants, preferring publishedPermissionScopes (with fallback to treat IDs as names), and adding diagnostics. Also adjust servicePrincipal fetch to request publishedPermissionScopes, reuse or generate PermissionSetId when updating, add stronger logging, and use -Force on table writes.
Copy file name to clipboardExpand all lines: Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Administration/Application Approval/Invoke-ExecCreateAppTemplate.ps1
# Look up application permission name from appRoles
@@ -284,16 +294,27 @@ function Invoke-ExecCreateAppTemplate {
284
294
Write-LogMessage-headers $Request.headers-API $APINAME-message "Application permission $($Access.id) not found in $ResourceAppId appRoles"-Sev 'Warning'
285
295
}
286
296
} elseif ($Access.type-eq'Scope') {
287
-
# Look up delegated permission name from oauth2PermissionScopes
Write-Information"Found delegated permission in publishedPermissionScopes with value: $($OAuth2Permission.value)"
303
+
# Found the permission - use the value from the lookup
290
304
$PermObj= [PSCustomObject]@{
291
305
id=$Access.id
292
-
value=$PermissionScope.value# Use the claim value name, not the GUID
306
+
value=$OAuth2Permission.value
293
307
}
294
308
[void]$DelegatedPerms.Add($PermObj)
295
309
} else {
296
-
Write-LogMessage-headers $Request.headers-API $APINAME-message "Delegated permission $($Access.id) not found in $ResourceAppId oauth2PermissionScopes"-Sev 'Warning'
310
+
# Not found by ID - assume Access.id is already the permission name
311
+
Write-Information"Could not find delegated permission by ID - using provided ID as value: $($Access.id)"
Write-LogMessage-headers $Request.headers-API $APINAME-message "Permission set created with ID: $PermissionSetId for $($Permissions.Count) resource(s)"-Sev 'Info'
406
+
Write-LogMessage-headers $Request.headers-API $APINAME-message "Permission set saved with ID: $PermissionSetId for $($Permissions.Count) resource(s)"-Sev 'Info'
321
407
}
322
408
323
-
# Create the template
324
-
$Table=Get-CIPPTable-TableName 'templates'
325
-
$TemplateId= (New-Guid).Guid
326
-
327
409
$TemplateJson=@{
328
410
TemplateName="$DisplayName (Auto-created)"
329
411
AppId=$AppId
@@ -343,7 +425,7 @@ function Invoke-ExecCreateAppTemplate {
0 commit comments