2

我有几个 API,我正在将访问 Azure SQL 数据库的方式从简单的凭据更改为利用 Azure Active Directory 的托管服务标识模型。

我对旧的 .Net API 执行此操作没有问题,但我无法让新的 .NetCore API 执行相同的操作。我已经读过.NetCore 尚不支持这一点的可能性,但我不清楚这是否准确/真实。

我运行这段代码:

SqlConnection conn = new SqlConnection(_ConnectionString);
conn.AccessToken = (new AzureServiceTokenProvider()).GetAccessTokenAsync("https://database.windows.net/").Result;

并得到这个错误:

AzureServiceTokenProviderException: Parameters: Connectionstring: [No connection string specified], Resource: https://database.windows.net/, Authority: . Exception Message: Tried the following 3 methods to get an access token, but none of them worked.
Parameters: Connectionstring: [No connection string specified], Resource: https://database.windows.net/, Authority: . Exception Message: Tried to get token using Managed Service Identity. Unable to connect to the Managed Service Identity (MSI) endpoint. Please check that you are running on an Azure resource that has MSI setup.
Parameters: Connectionstring: [No connection string specified], Resource: https://database.windows.net/, Authority: . Exception Message: Tried to get token using Visual Studio. Access token could not be acquired. Visual Studio Token provider file not found at "C:\Users\simonb\AppData\Local\.IdentityService\AzureServiceAuth\tokenprovider.json"
Parameters: Connectionstring: [No connection string specified], Resource: https://database.windows.net/, Authority: . Exception Message: Tried to get token using Azure CLI. Access token could not be acquired. 

我不希望这可以通过 MSI 工作,因为我在本地运行它,但它应该通过方法 2 工作


*更新找到这篇相关文章:https ://github.com/Azure/azure-sdk-for-net/issues/3933

4

1 回答 1

1

我已经读过.NetCore 尚不支持这一点的可能性,但我不清楚这是否准确/真实。

简而言之,它在 .Net Core 2.1 中不支持

.NET Framework 4.6 及更高版本当前支持此方案,但.NET Core 2.1 不支持。.NET Core 2.2 确实支持该方案,但尚未包含在应用服务的默认图像中。

更多细节,你可以参考这篇文章

于 2018-10-19T06:21:30.990 回答