From 6fc1921e13bc16fd554b18d34a4bcf4c85b8e37b Mon Sep 17 00:00:00 2001
From: Paul Medynski <31868385+paulmedynski@users.noreply.github.com>
Date: Fri, 9 Oct 2026 13:55:44 -0300
Subject: [PATCH 1/2] - Expose authentication configuration handlers from
Abstractions - Defer executable authentication compatibility tests from #4816
to #4817 - Correct WAM expansion in authentication configuration docs (#4816)
- Clarify authentication configuration handlers are infrastructure types
---
...enticationProviderConfigurationSection.xml | 68 +++++++++++++++++++
.../Abstractions/src/Abstractions.csproj | 2 +
.../Abstractions/src/PackageReadme.md | 37 ++++++++++
...henticationProviderConfigurationSection.cs | 41 +++++++++++
.../AuthenticationConfigurationSchemaTest.cs | 32 +++++++++
.../Microsoft.Data.SqlClient.csproj | 6 ++
.../ref/Microsoft.Data.SqlClient.csproj | 6 ++
.../src/Microsoft.Data.SqlClient.nuspec | 4 +-
.../SqlAuthenticationProviderManager.cs | 43 ------------
.../src/TypeForwards.Abstractions.cs | 2 +
.../tests/UnitTests/TypeForwardTests.cs | 6 ++
11 files changed, 202 insertions(+), 45 deletions(-)
create mode 100644 src/Microsoft.Data.SqlClient.Extensions/Abstractions/doc/SqlAuthenticationProviderConfigurationSection.xml
create mode 100644 src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/SqlAuthenticationProviderConfigurationSection.cs
create mode 100644 src/Microsoft.Data.SqlClient.Extensions/Abstractions/test/AuthenticationConfigurationSchemaTest.cs
diff --git a/src/Microsoft.Data.SqlClient.Extensions/Abstractions/doc/SqlAuthenticationProviderConfigurationSection.xml b/src/Microsoft.Data.SqlClient.Extensions/Abstractions/doc/SqlAuthenticationProviderConfigurationSection.xml
new file mode 100644
index 0000000000..c7cec82757
--- /dev/null
+++ b/src/Microsoft.Data.SqlClient.Extensions/Abstractions/doc/SqlAuthenticationProviderConfigurationSection.xml
@@ -0,0 +1,68 @@
+
+
+
+
+
+ The configuration section definition for reading app.config.
+ This infrastructure type is not intended for direct use by application code.
+
+
+ Defines the legacy SqlAuthenticationProviders section for authentication configuration.
+
+ This type is public to support use across SqlClient assemblies and configuration
+ section activation. Applications should not instantiate, derive from, or access
+ this type directly.
+
+ Referencing this handler in an app.config section declaration is supported.
+
+
+
+ The name of the legacy authentication configuration section.
+
+
+ User-defined auth providers.
+ The collection of user-defined authentication providers.
+
+
+ User-defined initializer.
+ The assembly-qualified initializer type name, or an empty string when unset.
+
+
+ Application Client Id
+ The application client ID, or an empty string when unset.
+
+
+
+ Forwarded to ActiveDirectoryAuthenticationProviderOptions.UseWamBroker
+ when the Azure extension's default provider is auto-installed. Stored as a string so
+ that an unset attribute can be distinguished from useWamBroker="false"; the
+ runtime parses it with .
+
+ The Web Account Manager broker preference, or an empty string when unset.
+
+
+
+
+
+ The configuration section definition for reading app.config.
+ This infrastructure type is not intended for direct use by application code.
+
+
+ Defines the current SqlClientAuthenticationProviders section for authentication configuration.
+
+ This type is public to support use across SqlClient assemblies and configuration
+ section activation. Applications should not instantiate, derive from, or access
+ this type directly.
+
+ Referencing this handler in an app.config section declaration is supported.
+
+
+
+ The name of the current authentication configuration section.
+
+
+
diff --git a/src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/Abstractions.csproj b/src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/Abstractions.csproj
index 1c9b5cc8b6..ba3a673041 100644
--- a/src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/Abstractions.csproj
+++ b/src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/Abstractions.csproj
@@ -78,6 +78,8 @@
Condition="'$(ReferenceType)' == 'Project'" />
+
diff --git a/src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/PackageReadme.md b/src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/PackageReadme.md
index 69a2fa1b26..b546876561 100644
--- a/src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/PackageReadme.md
+++ b/src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/PackageReadme.md
@@ -18,6 +18,43 @@ This package supports:
- .NET Standard 2.0 (compatible with .NET Framework 4.6.1+, .NET Core 2.0+, and .NET 5+)
+## Authentication configuration
+
+The public `SqlAuthenticationProviderConfigurationSection` (legacy
+`SqlAuthenticationProviders`) and `SqlClientAuthenticationProviderConfigurationSection`
+(`SqlClientAuthenticationProviders`) handlers are defined in this package and forwarded
+from SqlClient. These are infrastructure types, public to support use across SqlClient
+assemblies and configuration section activation, not APIs for direct use by application
+code. Applications should not instantiate, derive from, or access them directly.
+Referencing the handlers in app.config section declarations is supported, and existing
+declarations naming `Microsoft.Data.SqlClient` remain valid.
+Section names, properties (`providers`, `initializerType`,
+`applicationClientId`, `useWamBroker`) and empty defaults are unchanged.
+
+`System.Configuration.ConfigurationManager` is a transitive compile dependency required
+by the handlers' configuration base types. Authentication initialization and provider
+loading remain in the driver.
+
+Merge the following example into the application's app.config, replacing
+`ExampleAuthenticationProvider, ExampleApp` with the assembly-qualified name of an
+application-defined `SqlAuthenticationProvider`. The handler declaration continues to
+name `Microsoft.Data.SqlClient`; the type forward resolves it to Abstractions.
+
+```xml
+
+
+
+
+
+
+
+
+
+
+
+```
+
## Installation
Install the package via NuGet:
diff --git a/src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/SqlAuthenticationProviderConfigurationSection.cs b/src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/SqlAuthenticationProviderConfigurationSection.cs
new file mode 100644
index 0000000000..4e3b4324bc
--- /dev/null
+++ b/src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/SqlAuthenticationProviderConfigurationSection.cs
@@ -0,0 +1,41 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.ComponentModel;
+using System.Configuration;
+
+namespace Microsoft.Data.SqlClient
+{
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public class SqlAuthenticationProviderConfigurationSection : ConfigurationSection
+ {
+ ///
+ public const string Name = "SqlAuthenticationProviders";
+
+ ///
+ [ConfigurationProperty("providers")]
+ public ProviderSettingsCollection Providers => (ProviderSettingsCollection)this["providers"];
+
+ ///
+ [ConfigurationProperty("initializerType")]
+ public string InitializerType => this["initializerType"] as string ?? string.Empty;
+
+ ///
+ [ConfigurationProperty("applicationClientId", IsRequired = false)]
+ public string ApplicationClientId => this["applicationClientId"] as string ?? string.Empty;
+
+ ///
+ [ConfigurationProperty("useWamBroker", IsRequired = false)]
+ public string UseWamBroker => this["useWamBroker"] as string ?? string.Empty;
+ }
+
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public class SqlClientAuthenticationProviderConfigurationSection : SqlAuthenticationProviderConfigurationSection
+ {
+ ///
+ public new const string Name = "SqlClientAuthenticationProviders";
+ }
+}
diff --git a/src/Microsoft.Data.SqlClient.Extensions/Abstractions/test/AuthenticationConfigurationSchemaTest.cs b/src/Microsoft.Data.SqlClient.Extensions/Abstractions/test/AuthenticationConfigurationSchemaTest.cs
new file mode 100644
index 0000000000..897e5f1425
--- /dev/null
+++ b/src/Microsoft.Data.SqlClient.Extensions/Abstractions/test/AuthenticationConfigurationSchemaTest.cs
@@ -0,0 +1,32 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.ComponentModel;
+using System.Configuration;
+
+namespace Microsoft.Data.SqlClient.Extensions.Abstractions.Test;
+
+/// Pins authentication section names, configuration properties and defaults in Abstractions.
+public class AuthenticationConfigurationSchemaTest
+{
+ /// Both infrastructure-only handlers preserve their schema and remain hidden from IntelliSense.
+ [Theory]
+ [InlineData(typeof(SqlAuthenticationProviderConfigurationSection), "SqlAuthenticationProviders")]
+ [InlineData(typeof(SqlClientAuthenticationProviderConfigurationSection), "SqlClientAuthenticationProviders")]
+ public void HandlerContractIsPreserved(Type type, string sectionName)
+ {
+ var editorBrowsable = Assert.IsType(
+ Assert.Single(type.GetCustomAttributes(typeof(EditorBrowsableAttribute), inherit: false)));
+ Assert.Equal(EditorBrowsableState.Never, editorBrowsable.State);
+ var section = Assert.IsAssignableFrom(Activator.CreateInstance(type));
+ Assert.Equal(new[] { "applicationClientId", "initializerType", "providers", "useWamBroker" },
+ section.ElementInformation.Properties.Cast()
+ .Select(property => property.Name).OrderBy(name => name, StringComparer.Ordinal));
+ Assert.IsType(section.ElementInformation.Properties["providers"].Value);
+ Assert.Equal(sectionName, type.GetField("Name")!.GetRawConstantValue());
+ Assert.Equal(string.Empty, section.ElementInformation.Properties["initializerType"].Value);
+ Assert.Equal(string.Empty, section.ElementInformation.Properties["applicationClientId"].Value);
+ Assert.Equal(string.Empty, section.ElementInformation.Properties["useWamBroker"].Value);
+ }
+}
diff --git a/src/Microsoft.Data.SqlClient/notsupported/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/notsupported/Microsoft.Data.SqlClient.csproj
index 8f6d6522e3..8edf47037c 100644
--- a/src/Microsoft.Data.SqlClient/notsupported/Microsoft.Data.SqlClient.csproj
+++ b/src/Microsoft.Data.SqlClient/notsupported/Microsoft.Data.SqlClient.csproj
@@ -185,6 +185,12 @@
+
+
+
+
+
+
$(AssemblyName).$(TargetFramework).notsupported.cs
diff --git a/src/Microsoft.Data.SqlClient/ref/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/ref/Microsoft.Data.SqlClient.csproj
index a6e7a0b356..e40acac1c6 100644
--- a/src/Microsoft.Data.SqlClient/ref/Microsoft.Data.SqlClient.csproj
+++ b/src/Microsoft.Data.SqlClient/ref/Microsoft.Data.SqlClient.csproj
@@ -212,4 +212,10 @@
+
+
+
+
+
+
diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft.Data.SqlClient.nuspec b/src/Microsoft.Data.SqlClient/src/Microsoft.Data.SqlClient.nuspec
index ac3dd2c6ab..9b20f16e3f 100644
--- a/src/Microsoft.Data.SqlClient/src/Microsoft.Data.SqlClient.nuspec
+++ b/src/Microsoft.Data.SqlClient/src/Microsoft.Data.SqlClient.nuspec
@@ -60,7 +60,7 @@
-
+
@@ -72,7 +72,7 @@
-
+
diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlAuthenticationProviderManager.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlAuthenticationProviderManager.cs
index 3635b0b0d6..4875334795 100644
--- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlAuthenticationProviderManager.cs
+++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlAuthenticationProviderManager.cs
@@ -516,49 +516,6 @@ private static string GetProviderType(SqlAuthenticationProvider? provider)
}
}
- ///
- /// The configuration section definition for reading app.config.
- ///
- internal class SqlAuthenticationProviderConfigurationSection : ConfigurationSection
- {
- public const string Name = "SqlAuthenticationProviders";
-
- ///
- /// User-defined auth providers.
- ///
- [ConfigurationProperty("providers")]
- public ProviderSettingsCollection Providers => (ProviderSettingsCollection)this["providers"];
-
- ///
- /// User-defined initializer.
- ///
- [ConfigurationProperty("initializerType")]
- public string InitializerType => this["initializerType"] as string ?? string.Empty;
-
- ///
- /// Application Client Id
- ///
- [ConfigurationProperty("applicationClientId", IsRequired = false)]
- public string ApplicationClientId => this["applicationClientId"] as string ?? string.Empty;
-
- ///
- /// Forwarded to ActiveDirectoryAuthenticationProviderOptions.UseWamBroker
- /// when the Azure extension's default provider is auto-installed. Stored as a string so
- /// that an unset attribute can be distinguished from useWamBroker="false"; the
- /// runtime parses it with .
- ///
- [ConfigurationProperty("useWamBroker", IsRequired = false)]
- public string UseWamBroker => this["useWamBroker"] as string ?? string.Empty;
- }
-
- ///
- /// The configuration section definition for reading app.config.
- ///
- internal class SqlClientAuthenticationProviderConfigurationSection : SqlAuthenticationProviderConfigurationSection
- {
- public new const string Name = "SqlClientAuthenticationProviders";
- }
-
///
public abstract class SqlAuthenticationInitializer
{
diff --git a/src/Microsoft.Data.SqlClient/src/TypeForwards.Abstractions.cs b/src/Microsoft.Data.SqlClient/src/TypeForwards.Abstractions.cs
index f8272c5d2b..eeaf2dfb51 100644
--- a/src/Microsoft.Data.SqlClient/src/TypeForwards.Abstractions.cs
+++ b/src/Microsoft.Data.SqlClient/src/TypeForwards.Abstractions.cs
@@ -7,3 +7,5 @@
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(Microsoft.Data.SqlClient.SqlAuthenticationProvider))]
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(Microsoft.Data.SqlClient.SqlAuthenticationProviderException))]
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(Microsoft.Data.SqlClient.SqlAuthenticationToken))]
+[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(Microsoft.Data.SqlClient.SqlAuthenticationProviderConfigurationSection))]
+[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(Microsoft.Data.SqlClient.SqlClientAuthenticationProviderConfigurationSection))]
diff --git a/src/Microsoft.Data.SqlClient/tests/UnitTests/TypeForwardTests.cs b/src/Microsoft.Data.SqlClient/tests/UnitTests/TypeForwardTests.cs
index 8cb9811933..ed11feb494 100644
--- a/src/Microsoft.Data.SqlClient/tests/UnitTests/TypeForwardTests.cs
+++ b/src/Microsoft.Data.SqlClient/tests/UnitTests/TypeForwardTests.cs
@@ -8,16 +8,20 @@
namespace Microsoft.Data.SqlClient.UnitTests
{
+ /// Verifies relocated public types remain resolvable through the driver assembly.
public class TypeForwardTests
{
private static readonly Assembly s_sqlClientAssembly = typeof(SqlConnection).Assembly;
+ /// Type forwards preserve resolution through the original assembly name.
[Theory]
[InlineData("Microsoft.Data.SqlClient.SqlAuthenticationMethod", true)]
[InlineData("Microsoft.Data.SqlClient.SqlAuthenticationParameters", false)]
[InlineData("Microsoft.Data.SqlClient.SqlAuthenticationProvider", false)]
[InlineData("Microsoft.Data.SqlClient.SqlAuthenticationProviderException", false)]
[InlineData("Microsoft.Data.SqlClient.SqlAuthenticationToken", false)]
+ [InlineData("Microsoft.Data.SqlClient.SqlAuthenticationProviderConfigurationSection", false)]
+ [InlineData("Microsoft.Data.SqlClient.SqlClientAuthenticationProviderConfigurationSection", false)]
public void AbstractionsType_CanBeLoadedFromSqlClientAssembly(string typeName, bool isEnum)
{
// Types moved to the Abstractions assembly must remain loadable via the
@@ -26,6 +30,8 @@ public void AbstractionsType_CanBeLoadedFromSqlClientAssembly(string typeName, b
Assert.NotNull(type);
Assert.Equal(isEnum, type.IsEnum);
+ Assert.True(type.IsPublic);
+ Assert.Same(type, Type.GetType(typeName + ", Microsoft.Data.SqlClient", throwOnError: true));
// Assert that the assembly containing the type is the Abstractions assembly.
Assert.Equal("Microsoft.Data.SqlClient.Extensions.Abstractions", type.Assembly.GetName().Name);
From 53603d373eab086d065f4cd01737411dceb2daf4 Mon Sep 17 00:00:00 2001
From: Paul Medynski <31868385+paulmedynski@users.noreply.github.com>
Date: Thu, 22 Oct 2026 18:42:13 -0300
Subject: [PATCH 2/2] Address authentication configuration review feedback
(#4816)
Use framework configuration in the net462 Abstractions target.
Expose sealed sibling handlers with separate source and XML documentation.
Keep driver configuration normalization as a temporary bridge to #4821.
Cover real legacy/current configuration activation and preserved reader behavior.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
...enticationProviderConfigurationSection.xml | 21 +--
...enticationProviderConfigurationSection.xml | 49 ++++++
.../Abstractions/src/Abstractions.csproj | 7 +-
.../Abstractions/src/PackageReadme.md | 13 +-
...henticationProviderConfigurationSection.cs | 9 +-
...henticationProviderConfigurationSection.cs | 33 ++++
.../AuthenticationConfigurationSchemaTest.cs | 14 ++
.../SqlAuthenticationProviderManager.cs | 59 +++++--
.../AuthenticationConfigurationTest.cs | 157 ++++++++++++++++++
.../SqlClient/EnableAppConfigSwitchTest.cs | 2 +-
10 files changed, 318 insertions(+), 46 deletions(-)
create mode 100644 src/Microsoft.Data.SqlClient.Extensions/Abstractions/doc/SqlClientAuthenticationProviderConfigurationSection.xml
create mode 100644 src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/SqlClientAuthenticationProviderConfigurationSection.cs
create mode 100644 src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/AuthenticationConfigurationTest.cs
diff --git a/src/Microsoft.Data.SqlClient.Extensions/Abstractions/doc/SqlAuthenticationProviderConfigurationSection.xml b/src/Microsoft.Data.SqlClient.Extensions/Abstractions/doc/SqlAuthenticationProviderConfigurationSection.xml
index c7cec82757..b3f303ad75 100644
--- a/src/Microsoft.Data.SqlClient.Extensions/Abstractions/doc/SqlAuthenticationProviderConfigurationSection.xml
+++ b/src/Microsoft.Data.SqlClient.Extensions/Abstractions/doc/SqlAuthenticationProviderConfigurationSection.xml
@@ -17,6 +17,7 @@ See the LICENSE file in the project root for more information.
section activation. Applications should not instantiate, derive from, or access
this type directly.
+ This sealed handler derives directly from .
Referencing this handler in an app.config section declaration is supported.
@@ -45,24 +46,4 @@ See the LICENSE file in the project root for more information.
The Web Account Manager broker preference, or an empty string when unset.
-
-
-
- The configuration section definition for reading app.config.
- This infrastructure type is not intended for direct use by application code.
-
-
- Defines the current SqlClientAuthenticationProviders section for authentication configuration.
-
- This type is public to support use across SqlClient assemblies and configuration
- section activation. Applications should not instantiate, derive from, or access
- this type directly.
-
- Referencing this handler in an app.config section declaration is supported.
-
-
-
- The name of the current authentication configuration section.
-
-
diff --git a/src/Microsoft.Data.SqlClient.Extensions/Abstractions/doc/SqlClientAuthenticationProviderConfigurationSection.xml b/src/Microsoft.Data.SqlClient.Extensions/Abstractions/doc/SqlClientAuthenticationProviderConfigurationSection.xml
new file mode 100644
index 0000000000..32b93057ec
--- /dev/null
+++ b/src/Microsoft.Data.SqlClient.Extensions/Abstractions/doc/SqlClientAuthenticationProviderConfigurationSection.xml
@@ -0,0 +1,49 @@
+
+
+
+
+
+ The configuration section definition for reading app.config.
+ This infrastructure type is not intended for direct use by application code.
+
+
+ Defines the current SqlClientAuthenticationProviders section for authentication configuration.
+
+ This type is public to support use across SqlClient assemblies and configuration
+ section activation. Applications should not instantiate, derive from, or access
+ this type directly.
+
+ This sealed handler derives directly from .
+ Referencing this handler in an app.config section declaration is supported.
+
+
+
+ The name of the current authentication configuration section.
+
+
+ User-defined auth providers.
+ The collection of user-defined authentication providers.
+
+
+ User-defined initializer.
+ The assembly-qualified initializer type name, or an empty string when unset.
+
+
+ Application Client Id
+ The application client ID, or an empty string when unset.
+
+
+
+ Forwarded to ActiveDirectoryAuthenticationProviderOptions.UseWamBroker
+ when the Azure extension's default provider is auto-installed. Stored as a string so
+ that an unset attribute can be distinguished from useWamBroker="false"; the
+ runtime parses it with .
+
+ The Web Account Manager broker preference, or an empty string when unset.
+
+
+
diff --git a/src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/Abstractions.csproj b/src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/Abstractions.csproj
index ba3a673041..9b33638ff7 100644
--- a/src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/Abstractions.csproj
+++ b/src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/Abstractions.csproj
@@ -2,7 +2,7 @@
Microsoft.Data.SqlClient.Extensions.Abstractions
- netstandard2.0
+ net462;netstandard2.0
@@ -78,6 +78,11 @@
Condition="'$(ReferenceType)' == 'Project'" />
+
+
+
+
+
diff --git a/src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/PackageReadme.md b/src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/PackageReadme.md
index b546876561..d9b12d9194 100644
--- a/src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/PackageReadme.md
+++ b/src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/PackageReadme.md
@@ -16,6 +16,7 @@ The abstractions package allows for:
This package supports:
+- .NET Framework 4.6.2 (uses the framework's `System.Configuration` assembly)
- .NET Standard 2.0 (compatible with .NET Framework 4.6.1+, .NET Core 2.0+, and .NET 5+)
## Authentication configuration
@@ -23,7 +24,9 @@ This package supports:
The public `SqlAuthenticationProviderConfigurationSection` (legacy
`SqlAuthenticationProviders`) and `SqlClientAuthenticationProviderConfigurationSection`
(`SqlClientAuthenticationProviders`) handlers are defined in this package and forwarded
-from SqlClient. These are infrastructure types, public to support use across SqlClient
+from SqlClient. Both are sealed and derive directly from `ConfigurationSection`, with
+the same configuration schema and no inheritance relationship between the handlers.
+These are infrastructure types, public to support use across SqlClient
assemblies and configuration section activation, not APIs for direct use by application
code. Applications should not instantiate, derive from, or access them directly.
Referencing the handlers in app.config section declarations is supported, and existing
@@ -31,9 +34,11 @@ declarations naming `Microsoft.Data.SqlClient` remain valid.
Section names, properties (`providers`, `initializerType`,
`applicationClientId`, `useWamBroker`) and empty defaults are unchanged.
-`System.Configuration.ConfigurationManager` is a transitive compile dependency required
-by the handlers' configuration base types. Authentication initialization and provider
-loading remain in the driver.
+For the .NET Standard target, `System.Configuration.ConfigurationManager` is a transitive
+compile dependency required by the handlers' configuration base types. The .NET Framework
+target uses the framework's `System.Configuration` instead, without introducing a
+ConfigurationManager package dependency. Authentication initialization and provider loading
+remain in the driver, and the modern section continues to take precedence over the legacy one.
Merge the following example into the application's app.config, replacing
`ExampleAuthenticationProvider, ExampleApp` with the assembly-qualified name of an
diff --git a/src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/SqlAuthenticationProviderConfigurationSection.cs b/src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/SqlAuthenticationProviderConfigurationSection.cs
index 4e3b4324bc..2db5ab3d89 100644
--- a/src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/SqlAuthenticationProviderConfigurationSection.cs
+++ b/src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/SqlAuthenticationProviderConfigurationSection.cs
@@ -9,7 +9,7 @@ namespace Microsoft.Data.SqlClient
{
///
[EditorBrowsable(EditorBrowsableState.Never)]
- public class SqlAuthenticationProviderConfigurationSection : ConfigurationSection
+ public sealed class SqlAuthenticationProviderConfigurationSection : ConfigurationSection
{
///
public const string Name = "SqlAuthenticationProviders";
@@ -31,11 +31,4 @@ public class SqlAuthenticationProviderConfigurationSection : ConfigurationSectio
public string UseWamBroker => this["useWamBroker"] as string ?? string.Empty;
}
- ///
- [EditorBrowsable(EditorBrowsableState.Never)]
- public class SqlClientAuthenticationProviderConfigurationSection : SqlAuthenticationProviderConfigurationSection
- {
- ///
- public new const string Name = "SqlClientAuthenticationProviders";
- }
}
diff --git a/src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/SqlClientAuthenticationProviderConfigurationSection.cs b/src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/SqlClientAuthenticationProviderConfigurationSection.cs
new file mode 100644
index 0000000000..406be48fc0
--- /dev/null
+++ b/src/Microsoft.Data.SqlClient.Extensions/Abstractions/src/SqlClientAuthenticationProviderConfigurationSection.cs
@@ -0,0 +1,33 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.ComponentModel;
+using System.Configuration;
+
+namespace Microsoft.Data.SqlClient
+{
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public sealed class SqlClientAuthenticationProviderConfigurationSection : ConfigurationSection
+ {
+ ///
+ public const string Name = "SqlClientAuthenticationProviders";
+
+ ///
+ [ConfigurationProperty("providers")]
+ public ProviderSettingsCollection Providers => (ProviderSettingsCollection)this["providers"];
+
+ ///
+ [ConfigurationProperty("initializerType")]
+ public string InitializerType => this["initializerType"] as string ?? string.Empty;
+
+ ///
+ [ConfigurationProperty("applicationClientId", IsRequired = false)]
+ public string ApplicationClientId => this["applicationClientId"] as string ?? string.Empty;
+
+ ///
+ [ConfigurationProperty("useWamBroker", IsRequired = false)]
+ public string UseWamBroker => this["useWamBroker"] as string ?? string.Empty;
+ }
+}
diff --git a/src/Microsoft.Data.SqlClient.Extensions/Abstractions/test/AuthenticationConfigurationSchemaTest.cs b/src/Microsoft.Data.SqlClient.Extensions/Abstractions/test/AuthenticationConfigurationSchemaTest.cs
index 897e5f1425..ad7610b6e1 100644
--- a/src/Microsoft.Data.SqlClient.Extensions/Abstractions/test/AuthenticationConfigurationSchemaTest.cs
+++ b/src/Microsoft.Data.SqlClient.Extensions/Abstractions/test/AuthenticationConfigurationSchemaTest.cs
@@ -16,6 +16,8 @@ public class AuthenticationConfigurationSchemaTest
[InlineData(typeof(SqlClientAuthenticationProviderConfigurationSection), "SqlClientAuthenticationProviders")]
public void HandlerContractIsPreserved(Type type, string sectionName)
{
+ Assert.True(type.IsSealed);
+ Assert.Equal(typeof(ConfigurationSection), type.BaseType);
var editorBrowsable = Assert.IsType(
Assert.Single(type.GetCustomAttributes(typeof(EditorBrowsableAttribute), inherit: false)));
Assert.Equal(EditorBrowsableState.Never, editorBrowsable.State);
@@ -29,4 +31,16 @@ public void HandlerContractIsPreserved(Type type, string sectionName)
Assert.Equal(string.Empty, section.ElementInformation.Properties["applicationClientId"].Value);
Assert.Equal(string.Empty, section.ElementInformation.Properties["useWamBroker"].Value);
}
+
+#if NETFRAMEWORK
+ /// The net462 handlers use framework configuration without adding ConfigurationManager.
+ [Fact]
+ public void HandlersUseFrameworkConfiguration()
+ {
+ Assert.Equal("System.Configuration", typeof(ConfigurationSection).Assembly.GetName().Name);
+ Assert.DoesNotContain(
+ typeof(SqlAuthenticationProviderConfigurationSection).Assembly.GetReferencedAssemblies(),
+ assembly => assembly.Name == "System.Configuration.ConfigurationManager");
+ }
+#endif
}
diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlAuthenticationProviderManager.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlAuthenticationProviderManager.cs
index 4875334795..a49ac86acd 100644
--- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlAuthenticationProviderManager.cs
+++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlAuthenticationProviderManager.cs
@@ -29,7 +29,7 @@ internal sealed class SqlAuthenticationProviderManager
static SqlAuthenticationProviderManager()
{
- TryReadConfigurationSection(out SqlAuthenticationProviderConfigurationSection? configurationSection);
+ TryReadConfigurationSection(out AuthenticationConfiguration? configurationSection);
Instance = new SqlAuthenticationProviderManager(configurationSection);
@@ -178,7 +178,7 @@ TypeInitializationException or
///
/// Constructor.
///
- private SqlAuthenticationProviderManager(SqlAuthenticationProviderConfigurationSection? configSection)
+ private SqlAuthenticationProviderManager(AuthenticationConfiguration? configSection)
{
var methodName = "Ctor";
@@ -422,7 +422,7 @@ internal static bool SetProvider(SqlAuthenticationMethod authenticationMethod, S
/// Separated from the static constructor so that it can be tested: the
/// constructor runs once per process, before any test can observe it.
///
- internal static bool TryReadConfigurationSection(out SqlAuthenticationProviderConfigurationSection? configurationSection)
+ internal static bool TryReadConfigurationSection(out AuthenticationConfiguration? configurationSection)
{
configurationSection = null;
@@ -433,13 +433,7 @@ internal static bool TryReadConfigurationSection(out SqlAuthenticationProviderCo
try
{
- // New configuration section "SqlClientAuthenticationProviders" for Microsoft.Data.SqlClient accepted to avoid conflicts with older one.
- configurationSection = FetchConfigurationSection(SqlClientAuthenticationProviderConfigurationSection.Name);
- if (configurationSection == null)
- {
- // If configuration section is not yet found, try with old Configuration Section name for backwards compatibility
- configurationSection = FetchConfigurationSection(SqlAuthenticationProviderConfigurationSection.Name);
- }
+ configurationSection = ReadConfigurationSection(ConfigurationManager.GetSection);
}
catch (ConfigurationErrorsException e)
{
@@ -450,19 +444,38 @@ internal static bool TryReadConfigurationSection(out SqlAuthenticationProviderCo
return true;
}
+ internal static AuthenticationConfiguration? ReadConfigurationSection(Func getSection)
+ {
+ var current = FetchConfigurationSection(
+ SqlClientAuthenticationProviderConfigurationSection.Name, getSection);
+ if (current is not null)
+ {
+ return new AuthenticationConfiguration(
+ current.ApplicationClientId, current.InitializerType, current.UseWamBroker, current.Providers);
+ }
+
+ var legacy = FetchConfigurationSection(
+ SqlAuthenticationProviderConfigurationSection.Name, getSection);
+ return legacy is null
+ ? null
+ : new AuthenticationConfiguration(
+ legacy.ApplicationClientId, legacy.InitializerType, legacy.UseWamBroker, legacy.Providers);
+ }
+
///
/// Fetches provided configuration section from app.config file.
/// Does not support reading from appsettings.json yet.
///
///
///
+ /// Reads a section from the application or an isolated configuration file.
///
- private static T? FetchConfigurationSection(string name) where T : class
+ private static T? FetchConfigurationSection(string name, Func getSection) where T : class
{
Type t = typeof(T);
// TODO: Support reading configuration from appsettings.json for .NET runtime applications.
- object section = ConfigurationManager.GetSection(name);
+ object? section = getSection(name);
if (section != null)
{
if (section is ConfigurationSection configSection && configSection.GetType() == t)
@@ -514,6 +527,28 @@ private static string GetProviderType(SqlAuthenticationProvider? provider)
}
return provider.GetType().FullName ?? "unknown";
}
+
+ // Temporary bridge for the current driver reader. Remove with this manager in #4821,
+ // when the Abstractions registry takes over using SqlAuthenticationConfiguration.
+ internal sealed class AuthenticationConfiguration
+ {
+ internal AuthenticationConfiguration(
+ string applicationClientId,
+ string initializerType,
+ string useWamBroker,
+ ProviderSettingsCollection providers)
+ {
+ ApplicationClientId = applicationClientId;
+ InitializerType = initializerType;
+ UseWamBroker = useWamBroker;
+ Providers = providers;
+ }
+
+ internal string ApplicationClientId { get; }
+ internal string InitializerType { get; }
+ internal string UseWamBroker { get; }
+ internal ProviderSettingsCollection Providers { get; }
+ }
}
///
diff --git a/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/AuthenticationConfigurationTest.cs b/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/AuthenticationConfigurationTest.cs
new file mode 100644
index 0000000000..3323c70241
--- /dev/null
+++ b/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/AuthenticationConfigurationTest.cs
@@ -0,0 +1,157 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Collections.Generic;
+using System.Configuration;
+using System.IO;
+using Xunit;
+
+namespace Microsoft.Data.SqlClient.UnitTests;
+
+/// Verifies real configuration files activate forwarded handlers and preserve reader behavior.
+public class AuthenticationConfigurationTest
+{
+ /// Both driver-qualified declarations load the sealed handler and retain every configured value.
+ [Theory]
+ [InlineData("SqlAuthenticationProviders", typeof(SqlAuthenticationProviderConfigurationSection))]
+ [InlineData("SqlClientAuthenticationProviders", typeof(SqlClientAuthenticationProviderConfigurationSection))]
+ public void DriverQualifiedSectionPreservesValues(string sectionName, Type handlerType)
+ {
+ WithConfiguration(
+ $"",
+ $@"<{sectionName} applicationClientId='configured-client' initializerType='Example.Initializer, Example' useWamBroker='false'>
+
+
+
+ {sectionName}>",
+ configuration =>
+ {
+ object section = configuration.GetSection(sectionName);
+ Assert.Equal(handlerType, section.GetType());
+ Assert.Equal("Microsoft.Data.SqlClient.Extensions.Abstractions", section.GetType().Assembly.GetName().Name);
+
+ var settings = SqlAuthenticationProviderManager.ReadConfigurationSection(configuration.GetSection);
+ Assert.NotNull(settings);
+ Assert.Equal("configured-client", settings.ApplicationClientId);
+ Assert.Equal("Example.Initializer, Example", settings.InitializerType);
+ Assert.Equal("false", settings.UseWamBroker);
+ var provider = Assert.Single(settings.Providers);
+ var providerSettings = Assert.IsType(provider);
+ Assert.Equal("active directory default", providerSettings.Name);
+ Assert.Equal("Example.Provider, Example", providerSettings.Type);
+ Assert.Equal("configured-value", providerSettings.Parameters["customOption"]);
+ });
+ }
+
+ /// Empty real sections preserve empty strings and an empty provider collection.
+ [Theory]
+ [InlineData("SqlAuthenticationProviders", typeof(SqlAuthenticationProviderConfigurationSection))]
+ [InlineData("SqlClientAuthenticationProviders", typeof(SqlClientAuthenticationProviderConfigurationSection))]
+ public void DriverQualifiedSectionPreservesDefaults(string sectionName, Type handlerType)
+ {
+ WithConfiguration(
+ $"",
+ $"<{sectionName} />",
+ configuration =>
+ {
+ var settings = SqlAuthenticationProviderManager.ReadConfigurationSection(configuration.GetSection);
+ Assert.NotNull(settings);
+ Assert.Equal(string.Empty, settings.ApplicationClientId);
+ Assert.Equal(string.Empty, settings.InitializerType);
+ Assert.Equal(string.Empty, settings.UseWamBroker);
+ Assert.Empty(settings.Providers);
+ });
+ }
+
+ /// The modern section takes precedence without reading the legacy section.
+ [Fact]
+ public void ModernSectionTakesPrecedence()
+ {
+ WithConfiguration(
+ @"
+ ",
+ @"
+ ",
+ configuration =>
+ {
+ List reads = new();
+ var settings = SqlAuthenticationProviderManager.ReadConfigurationSection(name =>
+ {
+ reads.Add(name);
+ return configuration.GetSection(name);
+ });
+ Assert.NotNull(settings);
+ Assert.Equal("modern-client", settings.ApplicationClientId);
+ Assert.Equal(new[] { "SqlClientAuthenticationProviders" }, reads);
+ });
+ }
+
+ /// When neither section exists, the reader checks both names and returns no settings.
+ [Fact]
+ public void MissingSectionsReturnNull()
+ {
+ WithConfiguration(string.Empty, string.Empty, configuration =>
+ {
+ List reads = new();
+ var settings = SqlAuthenticationProviderManager.ReadConfigurationSection(name =>
+ {
+ reads.Add(name);
+ return configuration.GetSection(name);
+ });
+ Assert.Null(settings);
+ Assert.Equal(new[] { "SqlClientAuthenticationProviders", "SqlAuthenticationProviders" }, reads);
+ });
+ }
+
+ /// A mismatched modern handler is ignored rather than accepted solely because its schema matches.
+ [Fact]
+ public void WrongModernHandlerFallsBackToLegacy()
+ {
+ WithConfiguration(
+ @"
+ ",
+ @"
+ ",
+ configuration =>
+ {
+ var settings = SqlAuthenticationProviderManager.ReadConfigurationSection(configuration.GetSection);
+ Assert.NotNull(settings);
+ Assert.Equal("legacy-client", settings.ApplicationClientId);
+ });
+ }
+
+ /// A malformed modern section still fails parsing instead of silently falling back.
+ [Fact]
+ public void MalformedModernSectionDoesNotFallBack()
+ {
+ WithConfiguration(
+ @"
+ ",
+ @"
+ ",
+ configuration => Assert.Throws(() =>
+ SqlAuthenticationProviderManager.ReadConfigurationSection(configuration.GetSection)));
+ }
+
+ /// Loads an isolated configuration file and removes it even when an assertion fails.
+ /// Configuration section declarations.
+ /// Configuration section values.
+ /// Assertions executed while the file exists.
+ private static void WithConfiguration(string declarations, string sections, Action assertConfiguration)
+ {
+ string path = Path.GetTempFileName();
+ try
+ {
+ File.WriteAllText(path, $"{declarations}{sections}");
+ var fileMap = new ExeConfigurationFileMap { ExeConfigFilename = path };
+ Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
+ assertConfiguration(configuration);
+ }
+ finally
+ {
+ File.Delete(path);
+ }
+ }
+}
diff --git a/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/EnableAppConfigSwitchTest.cs b/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/EnableAppConfigSwitchTest.cs
index c611d16f79..4399fb0098 100644
--- a/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/EnableAppConfigSwitchTest.cs
+++ b/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/EnableAppConfigSwitchTest.cs
@@ -99,7 +99,7 @@ public void AuthenticationProvidersAreReadOnlyWhenEnabled(bool enabled)
Assert.Equal(
enabled,
- SqlAuthenticationProviderManager.TryReadConfigurationSection(out SqlAuthenticationProviderConfigurationSection? section));
+ SqlAuthenticationProviderManager.TryReadConfigurationSection(out SqlAuthenticationProviderManager.AuthenticationConfiguration? section));
// No test host supplies the section, so it is null either way.
Assert.Null(section);