c# - 获取 Azure SQL Server 的 Azure AD token

标签 c# azure authentication azure-active-directory azure-sql-database

我正在尝试开发一个 Web 应用程序,该应用程序使用证书通过 AD 进行身份验证,然后获取 token 以连接到 SQL Azure 数据库。

我已按照https://azure.microsoft.com/en-us/documentation/articles/sql-database-aad-authentication/中的所有步骤进行操作和 https://github.com/Azure-Samples/active-directory-dotnet-daemon-certificate-credential除了我使用这里的代码示例 - https://blogs.msdn.microsoft.com/sqlsecurity/2016/02/09/token-based-authentication-support-for-azure-sql-db-using-azure-ad-auth/

一切都很顺利,直到我到达终点

result = await authContext.AcquireTokenAsync(sqlDBResourceId, certCred);

我不太确定要为sqlDBResourceId输入什么,我已经尝试过

"https://<databasename>.database.windows.net/"
"https://<databasename>.windows.net/"
"<databasename>"

但我总是得到

{"AADSTS50001: The application named https://databasename.database.windows.net/ was not found in the tenant named tenantname.onmicrosoft.com. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You might have sent your authentication request to the wrong tenant.\r\nTrace ID: \r\nCorrelation ID: \r\nTimestamp: 2016-08-09 23:35:38Z"}

当我使用 https://graph.windows.net/ 作为 sqlDBResourceId 时,我能够收到 token 。那么也许我没有正确设置租户-目录-域-数据库关系?任何关于从哪里开始的建议将不胜感激。

最佳答案

Jack Zeng 是正确的 - 不要试图弄乱代码示例中的默认资源字符串,只需使用 https://database.windows.net/ .

关于c# - 获取 Azure SQL Server 的 Azure AD token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38862095/

相关文章:

c# - 在 Xamarin Forms 中检测 Windows Phone 8.1 与 Windows Phone 上的 UWPapp

c# - Client-Unet 中未收到广播

c# - ASP.NET MVC 4 一些路由不工作

java - 如何在线创建和验证 Onedrive 或 Sharepoint 的 Webhook?

ios - Objective-C - DropboxSDK : (401) Authentication failed -

c# - 如何在 Visual Studio 中使用空格自动对齐相似的代码行

Azure 数据工厂 - 读取 JSON 数组并写入单个 CSV 文件

azure - 当功能分支使用不同的构建管道时,将功能分支合并到主分支的最佳方法是什么?

c# - .Net Core MVC 自定义登录屏幕

javascript - 同构应用程序中的用户配置文件