天青SqlManagementClient - 禁止用TokenCloudCredentials
问题描述:
我试图连接到蔚蓝我的SQL服务器,并列出从.NET应用程序的DBS,但我不断收到天青SqlManagementClient - 禁止用TokenCloudCredentials
ForbiddenError: The server failed to authenticate the request. Verify that the certificate is valid and is associated with this subscription.
即使我想使用带有TokenCloudCredentials的Sql管理客户端。
var authContext = new AuthenticationContext(authority);
var clientCredential = new ClientCredential(clientId, appKey);
var result = authContext.AcquireTokenAsync(resource, clientCredential).Result;
var credentials = new Microsoft.Azure.TokenCloudCredentials(subscriptionId, result.AccessToken);
var client = new SqlManagementClient(credentials);
try
{
var servers = await client.Servers.ListAsync();
}
catch (CloudException c)
{
Console.WriteLine(c.Message);
throw;
}
AD应用程序有权访问资源组和Azure管理API。 任何想法为什么它不断抱怨证书,而使用令牌?
编辑:我设法使用“新”流利的管理API。您需要创建与订阅相关的AD应用程序并有权访问资源组。然后只需创建凭证并初始化流畅的API。
using Microsoft.Azure.Management.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent.Authentication;
using Microsoft.Azure.Management.ResourceManager.Fluent.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AzureManagement
{
public class Program
{
public static void Main(string[] args)
{
var azureCredentials = new AzureCredentials(new
ServicePrincipalLoginInformation
{
ClientId = "clientId",
ClientSecret = "clientSecret="
}, "tenantId", AzureEnvironment.AzureGlobalCloud);
var _azure = Azure
.Configure()
.WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
.Authenticate(azureCredentials)
.WithSubscription("subscriptionId");
var sql = _azure.SqlServers.List().ToList();
foreach (var s in sql)
{
var dbs = s.Databases.List().ToList();
}
Console.ReadLine();
}
}
}
答
我不确定这是否被支持。请为此问题创建支持案例。