I am using these commands to connect:
Import-Module Microsoft.Graph.Authentication
*$body = @{
grant_type = “client_credentials”;
client_id = “feabd295-fd7d-45d1-8b5a-97f2abf4fe0e”;
client_secret = “”;
scope = “https://graph.microsoft.com/.default”;
}
$response = Invoke-RestMethod -Method Post -Uri https://login.microsoftonline.com/52da6ceb-c432-45d8-9cee-97902996ced9/oauth2/v2.0/token -Body $body
$accessToken = $response.access_token
$clientSecret = ConvertTo-SecureString $accessToken -AsPlainText -Force
Connect-MgGraph -AccessToken $clientSecret*
The client has Application.Read.All is it’s api permission but I am getting this error:
*Get-MgApplication_List: Insufficient privileges to complete the operation.
Status: 403 (Forbidden)
ErrorCode: Authorization_RequestDenied
Date: 2024-06-07T14:52:33
Headers:
Cache-Control : no-cache
Vary : Accept-Encoding
Strict-Transport-Security : max-age=31536000
request-id : 16af9717-1979-4df8-a630-19a1a6ae8eb6
client-request-id : c8e4d80e-c4ed-4285-b611-49781d4c70b8
x-ms-ags-diagnostic : {“ServerInfo”:{“DataCenter”:”UK South”,”Slice”:”E”,”Ring”:”5″,”ScaleUnit”:”004″,”RoleInstance”:”LO1PEPF0000310D”}}
x-ms-resource-unit : 2
Date : Fri, 07 Jun 2024 14:52:33 GMT*
Please help.
Tried command Get-MgApplication
Got this result:
*Get-MgApplication_List: Insufficient privileges to complete the operation.
Status: 403 (Forbidden)
ErrorCode: Authorization_RequestDenied
Date: 2024-06-07T14:52:33
Headers:
Cache-Control : no-cache
Vary : Accept-Encoding
Strict-Transport-Security : max-age=31536000
request-id : 16af9717-1979-4df8-a630-19a1a6ae8eb6
client-request-id : c8e4d80e-c4ed-4285-b611-49781d4c70b8
x-ms-ags-diagnostic : {“ServerInfo”:{“DataCenter”:”UK South”,”Slice”:”E”,”Ring”:”5″,”ScaleUnit”:”004″,”RoleInstance”:”LO1PEPF0000310D”}}
x-ms-resource-unit : 2
Date : Fri, 07 Jun 2024 14:52:33 GMT*