4

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.

Pratik Bhattacharya
  • 3,596
  • 2
  • 32
  • 60

1 Answers1

3

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

Tom Sun - MSFT
  • 24,161
  • 3
  • 30
  • 47
  • I have another application where I have ADO.NET running on ADO.NET Framework 4.6. I am able to inject the access token in the DB Connection but there doesn't seem to be any mechanism in .NET Core. – Pratik Bhattacharya Mar 22 '18 at 10:00
  • "f your project platform is .netcore, it is not supported currently." - I got my answer, thanks. – Pratik Bhattacharya Mar 22 '18 at 10:01
  • 1
    .NET Core 2.2 Preview 1 includes it https://github.com/dotnet/core/blob/master/release-notes/2.2/preview/2.2.0-preview1.md – carraua Sep 19 '18 at 09:53