When using the https://graph.microsoft.com/.default
API to PATCH an Application in Azure AD it fails with the error:
"code": "Authorization_RequestDenied",
"message": "Insufficient privileges to complete the operation.", ...
The call authenticates by Application permissions and the following are configured: Application.ReadWrite.All
, Directory.ReadWrite.All
.
$uri = "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token";
$resourceUrl = 'https://graph.microsoft.com/.default'
$body = @{ grant_type='client_credentials';client_id=$clientId;client_secret=$clientSecret;scope=$resourceUrl; }
$result = Invoke-RestMethod -Method Post -Uri $uri -Body $body
$accessToken = $result.access_token
$authHeader = "Bearer $accessToken"
$patchBody = '{
"displayName" : "dev2"
}'
Invoke-RestMethod -method PATCH -Uri https://graph.microsoft.com/v1.0/applications/$($app.Id) -Body $patchBody -ContentType application/json -Headers @{Authorization = $AuthHeader }
Here is the API permission:
Note: I do have access to perform a GET operation for the Application.
Is it possible to achieve this?