Connect to Azure SQL server via AAD Authentication using EF Core

我怕爱的太早我们不能终老 提交于 2020-01-02 05:13:51

问题


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.

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.


回答1:


Connect to Azure SQL server via AAD Authentication using EF Core

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.

so I am looking forward to using Microsoft.Azure.Services.AppAuthentication for getting the token from AAD

You could get the demo code from the document You could get the demo code from the document

 var azureServiceTokenProvider = new AzureServiceTokenProvider();
 string accessToken = await azureServiceTokenProvider.GetAccessTokenAsync("https://management.azure.com/").ConfigureAwait(false);

Update:

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



来源:https://stackoverflow.com/questions/49407321/connect-to-azure-sql-server-via-aad-authentication-using-ef-core

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!