我正在尝试阅读 azure 资源的见解。我收到的错误是:
Operation returned an invalid status code 'Forbidden'
服务原则在工作区的订阅中被赋予了“Log Analytics Reader”角色。
Microsoft.Azure.Management.ResourceManager.Fluent.Authentication.AzureCredentials credentials =
Microsoft.Azure.Management.ResourceManager.Fluent.SdkContext.AzureCredentialsFactory.FromServicePrincipal(
"clientId",
"clientSecret",
"tenantId",
Microsoft.Azure.Management.ResourceManager.Fluent.AzureEnvironment.AzureGlobalCloud);
var client = new Microsoft.Azure.OperationalInsights.OperationalInsightsDataClient(credentials);
client.WorkspaceId = @"workspaceId";
var results = client.QueryWithHttpMessagesAsync("union * | take 5").Result;
状态码的解决方案:未授权是使用委派权限,但我需要一个没有用户交互的身份验证令牌。