【问题标题】:.NetCore API fails to get token from Azure CLI using MSI.Net Core API 无法使用 MSI 从 Azure CLI 获取令牌
【发布时间】:2018-10-17 21:01:33
【问题描述】:

我有几个 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

【问题讨论】:

    标签: c# azure .net-core azure-sql-database azure-managed-identity


    【解决方案1】:

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

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

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

    更多详情可以参考这个article

    【讨论】:

      猜你喜欢
      • 2019-02-15
      • 1970-01-01
      • 1970-01-01
      • 2022-09-24
      • 2022-01-22
      • 2019-03-14
      • 2013-03-05
      • 2023-03-23
      • 2020-03-06
      相关资源
      最近更新 更多