Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Core - Create SqlConnection with AccessToken

My understanding is that in order to implement Azure AD Managed Service Identity access to a SQL Database in Azure, I would need to create a SqlConnection with a retrieved token.

To add that token to the SqlConnection, .NET 4.6+ has an AccessToken property to do this. .NET Core 2.0 does not.

Is there any way around this?

Implementing Azure AD Managed Service Identity in a core app doesn't seem possible at this point unless I am misunderstanding.

like image 506
KickinMhl Avatar asked Jan 25 '18 19:01

KickinMhl


2 Answers

As of SqlClient package 4.6.0, SqlConnection now supports AccessToken for SqlClient of .NET Core 2.2.

https://www.nuget.org/packages/System.Data.SqlClient/

like image 135
divega Avatar answered Oct 18 '22 07:10

divega


A workaround would be to store the connection string in Azure Key Vault and then implement MSI to retrieve it from Key Vault.

like image 38
Arturo Lucatero - MSFT Avatar answered Oct 18 '22 08:10

Arturo Lucatero - MSFT