2017-09-28 76 views
0

我試圖連接到蔚藍我的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(); 
     } 
    } 
} 

回答

1

我不確定這是否被支持。請爲此問題創建支持案例。