This repository provides a sample implementation of SqlAuthenticationProvider that can be used for ActiveDirectoryInteractive
authentication mode with System.Data.SqlClient as well as Microsoft.Data.SqlClient (with namespace toggle).
The CustomAuthProvider
implements SqlAuthenticationProvider
and the authentication is performed using MSAL (Microsoft.Identity.Client).
Provide details in the sample in the Program.cs
file:
appClientId
: Application Client ID of First Party App to be used for authentication (by default SqlClient's client id is used)appName
: Name of client application- Connection string details
DataSource
: Target Azure SQL Server endpointInitialCatalog
: Name of Azure Database instanceUserID
: Username for silent authentication (applicable when cache is persisted)
- Using Visual Studio, Build the solution.
- Using Dotnet CLI, run
dotnet build
- Run the exe:
bin\net48\SampleSqlAuthProvider.exe
- Using Dotnet CLI, run
dotnet run
Microsoft.Data.SqlClient package is referenced in the sample, and to use that, comment out the using System.Data.SqlClient
namespaces and uncomment using Microsoft.Data.SqlClient
in below files:
- Program.cs
- CustomAuthProvider.cs