Skip to content

Commit 70db11b

Browse files
Introduce samples project with direct reference to public MDS NuGet package
1 parent 125614c commit 70db11b

14 files changed

+117
-43
lines changed

src/Directory.Packages.props renamed to Directory.Packages.props

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
44
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
55
</PropertyGroup>
6-
76
<!-- ===================================================================== -->
87
<!-- Shared Dependencies -->
9-
108
<!-- Published -->
119
<ItemGroup>
1210
<!-- MDS and AKV -->
1311
<PackageVersion Include="Azure.Core" Version="1.49.0" />
12+
<PackageVersion Include="Microsoft.Identity.Client" Version="4.78.0" />
1413
</ItemGroup>
15-
1614
<!-- Published - Target Framework Specific Dependencies -->
1715
<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
1816
<!-- MDS and AKV -->
@@ -22,7 +20,6 @@
2220
<!-- MDS and AKV -->
2321
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="8.0.1" />
2422
</ItemGroup>
25-
2623
<!-- Internal -->
2724
<ItemGroup>
2825
<!-- MDS and AKV Tests -->
@@ -44,7 +41,6 @@
4441
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
4542
<PackageVersion Include="xunit.runner.console" Version="2.9.3" />
4643
</ItemGroup>
47-
4844
<!-- Internal - Target Framework Specific Dependencies -->
4945
<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
5046
<!-- MDS and AKV Tests -->
@@ -59,18 +55,15 @@
5955
-->
6056
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
6157
</ItemGroup>
62-
6358
<!-- ===================================================================== -->
6459
<!-- MDS Dependencies -->
65-
6660
<!-- Common Dependencies (.NET and .NET Framework) -->
6761
<ItemGroup>
6862
<PackageVersion Include="Azure.Identity" Version="1.16.0" />
6963
<PackageVersion Include="Microsoft.IdentityModel.JsonWebTokens" Version="8.14.0" />
7064
<PackageVersion Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="8.14.0" />
7165
<PackageVersion Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" />
7266
</ItemGroup>
73-
7467
<!-- Common Target Framework Specific Dependencies -->
7568
<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
7669
<PackageVersion Include="Microsoft.Bcl.Cryptography" Version="9.0.9" />
@@ -84,13 +77,11 @@
8477
<PackageVersion Include="System.Security.Cryptography.Pkcs" Version="8.0.1" />
8578
<PackageVersion Include="System.Text.Json" Version="8.0.6" />
8679
</ItemGroup>
87-
8880
<!-- .NET Dependencies -->
8981
<ItemGroup>
9082
<PackageVersion Include="Microsoft.Data.SqlClient.SNI.runtime" Version="6.0.2" />
9183
<PackageVersion Include="Microsoft.SqlServer.Server" Version="1.0.0" />
9284
</ItemGroup>
93-
9485
<!-- .NET Framework Dependencies -->
9586
<ItemGroup>
9687
<PackageVersion Include="Microsoft.Data.SqlClient.SNI" Version="6.0.2" />
@@ -102,17 +93,12 @@
10293
<PackageVersion Include="System.ValueTuple" Version="4.6.1" />
10394
<PackageVersion Include="System.Threading.Channels" Version="8.0.0" />
10495
</ItemGroup>
105-
10696
<!-- =================================================================== -->
10797
<!-- AKV Dependencies -->
108-
10998
<ItemGroup>
11099
<PackageVersion Include="Azure.Security.KeyVault.Keys" Version="4.8.0" />
111100
</ItemGroup>
112-
113101
<!-- =================================================================== -->
114102
<!-- MSS Dependencies -->
115-
116103
<!-- None -->
117-
118-
</Project>
104+
</Project>

doc/Directory.Packages.props

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project>
2+
<!-- Import parent Directory.Packages.props -->
3+
<Import Project="..\Directory.Packages.props" />
4+
<ItemGroup>
5+
<!-- Reference latest stable version of MDS and AKV provider -->
6+
<PackageVersion Include="Microsoft.Data.SqlClient" Version="6.1.2" />
7+
<PackageVersion Include="Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider" Version="6.1.2" />
8+
</ItemGroup>
9+
</Project>

doc/samples/AADAuthenticationCustomDeviceFlowCallback.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using Microsoft.Identity.Client;
55
using Microsoft.Data.SqlClient;
66

7-
namespace CustomAuthenticationProviderExamples
7+
namespace CustomDeviceCodeFlowAuthProviderExample
88
{
99
public class Program
1010
{

doc/samples/ApplicationClientIdAzureAuthenticationProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System;
33
using Microsoft.Data.SqlClient;
44

5-
namespace CustomAuthenticationProviderExamples
5+
namespace CustomAppIdAuthProviderExample
66
{
77
public class Program
88
{

doc/samples/AzureKeyVaultProviderExample.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* TODO: This sample file should be deleted as the AKV Provider Ctor API is no longer supported with supported versions of AKV provider and MDS.
3+
* Depends on: Delete documentation and sample reference in MS Docs first: https://learn.microsoft.com/en-us/sql/connect/ado-net/sql/azure-key-vault-example?view=sql-server-ver17#legacy-callback-implementation-design-example-with-v20
4+
*
5+
16
using System;
27
//<Snippet1>
38
using System.Collections.Generic;
@@ -23,7 +28,7 @@ public class AzureKeyVaultProviderExample
2328
public static void Main(string[] args)
2429
{
2530
// Initialize AKV provider
26-
SqlColumnEncryptionAzureKeyVaultProvider sqlColumnEncryptionAzureKeyVaultProvider = new SqlColumnEncryptionAzureKeyVaultProvider(AzureActiveDirectoryAuthenticationCallback);
31+
SqlColumnEncryptionAzureKeyVaultProvider sqlColumnEncryptionAzureKeyVaultProvider = new(AzureActiveDirectoryAuthenticationCallback);
2732
2833
// Register AKV provider
2934
SqlConnection.RegisterColumnEncryptionKeyStoreProviders(customProviders: new Dictionary<string, SqlColumnEncryptionKeyStoreProvider>(capacity: 1, comparer: StringComparer.OrdinalIgnoreCase)
@@ -258,3 +263,4 @@ public CustomerRecord(int id, string fName, string lName)
258263
}
259264
}
260265
//</Snippet1>
266+
*/

doc/samples/AzureKeyVaultProviderLegacyExample_2_0.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
1-
//<Snippet1>
1+
/**
2+
* TODO: This sample file should be deleted as the AKV Provider Ctor API is no longer supported with supported versions of AKV provider and MDS.
3+
* Depends on: Delete documentation and sample reference in MS Docs first: https://learn.microsoft.com/en-us/sql/connect/ado-net/sql/azure-key-vault-example?view=sql-server-ver17#legacy-callback-implementation-design-example-with-v20
4+
*
5+
6+
//< Snippet1>
27
using System;
38
using System.Collections.Generic;
9+
using System.IdentityModel.Tokens.Jwt;
10+
using System.Linq;
11+
using System.Net.Http;
412
using System.Security.Cryptography;
5-
using Azure.Identity;
6-
using Microsoft.Data.SqlClient;
13+
using System.Threading;
14+
using System.Threading.Tasks;
15+
using Azure.Core;
716
using Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider;
17+
using Newtonsoft.Json;
18+
using Newtonsoft.Json.Linq;
819
920
namespace Microsoft.Data.SqlClient.Samples
1021
{
@@ -366,3 +377,4 @@ public static async Task<string> AzureActiveDirectoryAuthenticationCallback(stri
366377
}
367378
}
368379
//</Snippet1>
380+
*/

doc/samples/AzureKeyVaultProviderWithEnclaveProviderExample_2_0.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
//<Snippet1>
33
using System.Collections.Generic;
44
using System.Security.Cryptography;
5-
using System.Threading.Tasks;
65
using Azure.Identity;
76
using Microsoft.Data.SqlClient;
87
using Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider;
98

10-
namespace AKVEnclaveExample
9+
namespace AKVEnclaveExample_2_0
1110
{
1211
class Program
1312
{

doc/samples/AzureKeyVaultProvider_ColumnEncryptionKeyCacheScope.cs

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
1-
// <Snippet1>
2-
class Program
1+
using System.Collections.Generic;
2+
using Azure.Identity;
3+
using Microsoft.Data.SqlClient;
4+
using Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider;
5+
6+
namespace AzureKeyVaultProviderExample
37
{
4-
static void Main()
8+
// <Snippet1>
9+
class Program
510
{
6-
using (SqlConnection connection = new SqlConnection(connectionString))
11+
private static string connectionString;
12+
13+
static void Main()
714
{
8-
using (SqlCommand command = connection.CreateCommand())
15+
using (SqlConnection connection = new SqlConnection(connectionString))
916
{
10-
Dictionary<string, SqlColumnEncryptionKeyStoreProvider> customKeyStoreProviders = new Dictionary<string, SqlColumnEncryptionKeyStoreProvider>();
11-
SqlColumnEncryptionAzureKeyVaultProvider azureKeyVaultProvider = new SqlColumnEncryptionAzureKeyVaultProvider();
12-
customKeyStoreProviders.Add(SqlColumnEncryptionAzureKeyVaultProvider.ProviderName, azureKeyVaultProvider);
13-
command.RegisterColumnEncryptionKeyStoreProvidersOnCommand(customKeyStoreProviders);
14-
// Perform database operation using Azure Key Vault Provider
15-
// Any decrypted column encryption keys will be cached
16-
} // Column encryption key cache of "azureKeyVaultProvider" is cleared when "azureKeyVaultProvider" goes out of scope
17+
using (SqlCommand command = connection.CreateCommand())
18+
{
19+
Dictionary<string, SqlColumnEncryptionKeyStoreProvider> customKeyStoreProviders = new Dictionary<string, SqlColumnEncryptionKeyStoreProvider>();
20+
SqlColumnEncryptionAzureKeyVaultProvider azureKeyVaultProvider = new SqlColumnEncryptionAzureKeyVaultProvider(new DefaultAzureCredential());
21+
customKeyStoreProviders.Add(SqlColumnEncryptionAzureKeyVaultProvider.ProviderName, azureKeyVaultProvider);
22+
command.RegisterColumnEncryptionKeyStoreProvidersOnCommand(customKeyStoreProviders);
23+
// Perform database operation using Azure Key Vault Provider
24+
// Any decrypted column encryption keys will be cached
25+
} // Column encryption key cache of "azureKeyVaultProvider" is cleared when "azureKeyVaultProvider" goes out of scope
26+
}
1727
}
1828
}
29+
// </Snippet1>
1930
}
20-
// </Snippet1>

doc/samples/CustomDeviceCodeFlowAzureAuthenticationProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using Microsoft.Data.SqlClient;
88
using Microsoft.Identity.Client;
99

10-
namespace CustomAuthenticationProviderExamples
10+
namespace CustomDeviceCodeFlowAuthProviderExample
1111
{
1212
/// <summary>
1313
/// Example demonstrating creating a custom device code flow authentication provider and attaching it to the driver.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Library</OutputType>
5+
<ImplicitUsings>disable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<LangVersion>Latest</LangVersion>
8+
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Azure.Identity" />
13+
<PackageReference Include="Azure.Core" />
14+
<PackageReference Include="Microsoft.Identity.Client" />
15+
<PackageReference Include="Microsoft.SqlServer.Server" />
16+
<PackageReference Include="Microsoft.Data.SqlClient" />
17+
<PackageReference Include="Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider" />
18+
<PackageReference Include="Newtonsoft.Json" />
19+
</ItemGroup>
20+
21+
<!-- .NET Framework references -->
22+
<ItemGroup Condition="$(TargetGroup) == 'netfx'">
23+
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" />
24+
<Reference Include="System.Transactions" />
25+
<Reference Include="System.Windows.Forms" />
26+
</ItemGroup>
27+
28+
</Project>

0 commit comments

Comments
 (0)