无法使用Azure服务令牌提供程序



我有一个Azure函数,它试图使用AzureServiceTokenProvider,但在调用GetAccessTokenAsync时抛出异常。

var tokenProvider = new AzureServiceTokenProvider();
var result = await tokenProvider.GetAccessTokenAsync("https://database.windows.net/");

当Managed Identities关闭时会引发此异常。

Parameters: Connection String: [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: Connection String: [No connection string specified], Resource: https://database.windows.net/, Authority: . Exception Message: Tried to get token using Managed Service Identity. Access token could not be acquired. An attempt was made to access a socket in a way forbidden by its access permissions.
Parameters: Connection String: [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 "D:localLocalAppData.IdentityServiceAzureServiceAuthtokenprovider.json"
Parameters: Connection String: [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. 'az' is not recognized as an internal or external command, operable program or batch file.

当启用托管标识时引发此异常。

[Error] Executed 'MyFunction' (Failed, Id=89446c8d-6d74-44e3-ae97-73ac31cbdb6b)
An attempt was made to access a socket in a way forbidden by its access permissions.

启用托管身份后会出现错误,因为您的数据库不允许使用功能应用程序
您可以通过
1修复此问题。转到Azure门户中的Azure数据库
2。单击IAM
3。添加角色
4。搜索您的功能应用程序
5。保存所有内容
6。重新运行功能应用

最新更新