【发布时间】:2018-12-23 20:14:53
【问题描述】:
我正在开发一个连接到 Microsoft Azure 的小型应用程序,列出属于某个资源组的所有数据库,并导出所有上述数据库。我正在为此使用Microsoft.WindowsAzure.Management.Sql 库。
在this guide 之后,我设法在 AD 中为我的应用程序设置了应用程序注册,并为其分配了Owner 角色(用于测试),通过 Azure 进行身份验证并获得访问令牌。
但是,当我尝试使用该令牌对数据库执行任何操作(例如列出所有数据库,使用 IServerOperations.List)时,我收到以下异常:
ForbiddenError: The server failed to authenticate the request. Verify that the certificate is valid and is associated with this subscription.
租户 ID、订阅 ID、客户端 ID 和客户端密码都是正确的,更改其中任何一个都会导致不同的异常,已经在身份验证阶段。
我该如何解决这个问题?如果正确答案是“切换到Microsoft.Azure.Management.Sql”,我完全可以接受,但如果可能的话,我至少想了解为什么会发生这种情况。
【问题讨论】:
-
您需要先删除或清除 Azure 帐户,通过添加新的 Azure 帐户为租户进行身份验证,然后选择订阅 ID。
标签: c# azure azure-sql-database azure-active-directory azure-management