https://github.com/cheenamalhotra/samplesqlauthprovider
Sample implementation of SqlAuthenticationProvider using MSAL for System.Data.SqlClient and Microsoft.Data.SqlClient
https://github.com/cheenamalhotra/samplesqlauthprovider
activedirectory authentication dotnet-framework interactive sqlclient
Last synced: about 2 months ago
JSON representation
Sample implementation of SqlAuthenticationProvider using MSAL for System.Data.SqlClient and Microsoft.Data.SqlClient
- Host: GitHub
- URL: https://github.com/cheenamalhotra/samplesqlauthprovider
- Owner: cheenamalhotra
- Created: 2023-03-24T16:30:32.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-01-17T04:40:13.000Z (over 2 years ago)
- Last Synced: 2025-01-09T05:39:34.597Z (over 1 year ago)
- Topics: activedirectory, authentication, dotnet-framework, interactive, sqlclient
- Language: C#
- Homepage:
- Size: 12.7 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Sample Sql Authentication Provider implementation
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).
## Configure the sample
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 endpoint
- `InitialCatalog`: Name of Azure Database instance
- `UserID`: Username for silent authentication (applicable when cache is persisted)
## How to build the sample
- Using Visual Studio, Build the solution.
- Using Dotnet CLI, run `dotnet build`
## How to run the sample
- Run the exe: `bin\net48\SampleSqlAuthProvider.exe`
- Using Dotnet CLI, run `dotnet run`
## Porting to Microsoft.Data.SqlClient
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