使用EF Core通过AAD身份验证连接到Azure SQL服务器 [英] Connect to Azure SQL server via AAD Authentication using EF Core
问题描述
Azure SQL Server支持AAD身份验证,我希望我的应用程序使用AAD身份验证而不是SQL Server管理员凭据连接到SQL Server。我正在使用EF Core连接到SQL,如何使EF Core使用AAD身份验证。
Azure SQL servers support AAD authentication, and I want my applications to connect to SQL server using AAD authentication and not SQL server admin credentials. I am using EF core to connect to SQL, how do I enable EF Core to use AAD authentication.
我的应用程序已部署在Azure App Service中,并且已启用MSI扩展,所以我期待使用 Microsoft.Azure.Services.AppAuthentication
从AAD获取令牌。
My application is deployed in Azure App Service and it has MSI extension enabled, so I am looking forward to using Microsoft.Azure.Services.AppAuthentication
for getting the token from AAD.
推荐答案
使用EF Core通过AAD身份验证连接到Azure SQL服务器
Connect to Azure SQL server via AAD Authentication using EF Core
如果您的项目平台是 .netcore ,则当前不支持
。我还在github上找到了问题。
If your project platform is .netcore, it is not supported
currently. I also find the issue on the github.
Or you could refer to this blog or another SO thread.
所以我期待使用Microsoft.Azure.Services.AppAuthentication从AAD获取令牌
so I am looking forward to using Microsoft.Azure.Services.AppAuthentication for getting the token from AAD
var azureServiceTokenProvider = new AzureServiceTokenProvider();
string accessToken = await azureServiceTokenProvider.GetAccessTokenAsync("https://management.azure.com/").ConfigureAwait(false);
更新:
感谢AlejandroC共享,.NET Core 2.2预览版1支持该功能,有关更多信息,请参考。NET Core 2.2预览1-2018年8月22日
Thanks for AlejandroC sharing, it is supported in .NET Core 2.2 Preview 1, for more information please refer .NET Core 2.2 Preview 1 - August 22, 2018
这篇关于使用EF Core通过AAD身份验证连接到Azure SQL服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!