Hey CRTL - apologies for not responding sooner - I get that when either my client secret expires or i have the wrong ID/secret, but i suppose it could also be permissions.
Try this powershell script with your tenant, clientid, clientsecret - the script authenticates and lists your intune devices.
$tenantId = "<your tenant ID>"
$clientId = "<your client ID>"
$clientSecret = "<your client secret>"
$scope = "https://graph.microsoft.com/.default"
$body = @{
client_id = $clientId
scope = $scope
client_secret = $clientSecret
grant_type = "client_credentials"
}
$tokenResponse = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token" -Method POST -Body $body
$accessToken = $tokenResponse.access_token
# Now use the token to call Intune
$headers = @{ Authorization = "Bearer $accessToken" }
Invoke-RestMethod -Uri "https://graph.microsoft.com/v1.0/deviceManagement/managedDevices" -Headers $headers