Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Comment thread
paulmedynski marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!--
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.
-->
<docs>
<members name="SqlAuthenticationProviderConfigurationSection">
<SqlAuthenticationProviderConfigurationSection>
<summary>
The configuration section definition for reading app.config.
This infrastructure type is not intended for direct use by application code.
</summary>
<remarks>
<para>Defines the legacy <c>SqlAuthenticationProviders</c> section for authentication configuration.</para>
<para>
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.
</para>
<para>This sealed handler derives directly from <see cref="T:System.Configuration.ConfigurationSection"/>.</para>
<para>Referencing this handler in an app.config section declaration is supported.</para>
</remarks>
</SqlAuthenticationProviderConfigurationSection>
<Name>
<summary>The name of the legacy authentication configuration section.</summary>
</Name>
<Providers>
<summary>User-defined auth providers.</summary>
<value>The collection of user-defined authentication providers.</value>
</Providers>
<InitializerType>
<summary>User-defined initializer.</summary>
<value>The assembly-qualified initializer type name, or an empty string when unset.</value>
</InitializerType>
<ApplicationClientId>
<summary>Application Client Id</summary>
<value>The application client ID, or an empty string when unset.</value>
</ApplicationClientId>
<UseWamBroker>
<summary>
Forwarded to <c>ActiveDirectoryAuthenticationProviderOptions.UseWamBroker</c>
when the Azure extension's default provider is auto-installed. Stored as a string so
that an unset attribute can be distinguished from <c>useWamBroker="false"</c>; the
runtime parses it with <see cref="M:System.Boolean.TryParse(System.String,System.Boolean@)"/>.
</summary>
<value>The Web Account Manager broker preference, or an empty string when unset.</value>
</UseWamBroker>
</members>
</docs>
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!--
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.
-->
<docs>
<members name="SqlClientAuthenticationProviderConfigurationSection">
<SqlClientAuthenticationProviderConfigurationSection>
<summary>
The configuration section definition for reading app.config.
This infrastructure type is not intended for direct use by application code.
</summary>
<remarks>
<para>Defines the current <c>SqlClientAuthenticationProviders</c> section for authentication configuration.</para>
<para>
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.
</para>
<para>This sealed handler derives directly from <see cref="T:System.Configuration.ConfigurationSection"/>.</para>
<para>Referencing this handler in an app.config section declaration is supported.</para>
</remarks>
</SqlClientAuthenticationProviderConfigurationSection>
<Name>
<summary>The name of the current authentication configuration section.</summary>
</Name>
<Providers>
<summary>User-defined auth providers.</summary>
<value>The collection of user-defined authentication providers.</value>
</Providers>
<InitializerType>
<summary>User-defined initializer.</summary>
<value>The assembly-qualified initializer type name, or an empty string when unset.</value>
</InitializerType>
<ApplicationClientId>
<summary>Application Client Id</summary>
<value>The application client ID, or an empty string when unset.</value>
</ApplicationClientId>
<UseWamBroker>
<summary>
Forwarded to <c>ActiveDirectoryAuthenticationProviderOptions.UseWamBroker</c>
when the Azure extension's default provider is auto-installed. Stored as a string so
that an unset attribute can be distinguished from <c>useWamBroker="false"</c>; the
runtime parses it with <see cref="M:System.Boolean.TryParse(System.String,System.Boolean@)"/>.
</summary>
<value>The Web Account Manager broker preference, or an empty string when unset.</value>
</UseWamBroker>
</members>
</docs>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!-- General Properties ============================================== -->
<PropertyGroup>
<AssemblyName>Microsoft.Data.SqlClient.Extensions.Abstractions</AssemblyName>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>net462;netstandard2.0</TargetFrameworks>
</PropertyGroup>

<!-- Compiler Options ================================================ -->
Expand Down Expand Up @@ -79,6 +79,13 @@
<PackageReference Include="Microsoft.Data.SqlClient.Internal.Logging"
Condition="'$(ReferenceType)' == 'Package'" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net462'">
<Reference Include="System.Configuration" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'net462'">
<PackageReference Include="System.Configuration.ConfigurationManager"
Comment thread
cheenamalhotra marked this conversation as resolved.
Resolved
PrivateAssets="contentfiles;build;buildTransitive;analyzers" />
</ItemGroup>

<!-- CodeGen Targets ================================================= -->
<Import Project="$(ToolsDir)targets\GenerateThisAssemblyCs.targets" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,50 @@ 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

The public `SqlAuthenticationProviderConfigurationSection` (legacy
`SqlAuthenticationProviders`) and `SqlClientAuthenticationProviderConfigurationSection`
(`SqlClientAuthenticationProviders`) handlers are defined in this package and forwarded
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
declarations naming `Microsoft.Data.SqlClient` remain valid.
Section names, properties (`providers`, `initializerType`,
`applicationClientId`, `useWamBroker`) and empty defaults are unchanged.

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
application-defined `SqlAuthenticationProvider`. The handler declaration continues to
name `Microsoft.Data.SqlClient`; the type forward resolves it to Abstractions.

```xml
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="SqlClientAuthenticationProviders"
type="Microsoft.Data.SqlClient.SqlClientAuthenticationProviderConfigurationSection, Microsoft.Data.SqlClient" />
</configSections>
<SqlClientAuthenticationProviders>
<providers>
<add name="active directory default" type="ExampleAuthenticationProvider, ExampleApp" />
</providers>
</SqlClientAuthenticationProviders>
</configuration>
```

## Installation

Install the package via NuGet:
Expand Down
Comment thread
paulmedynski marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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
{
/// <include file='../doc/SqlAuthenticationProviderConfigurationSection.xml' path='docs/members[@name="SqlAuthenticationProviderConfigurationSection"]/SqlAuthenticationProviderConfigurationSection/*'/>
[EditorBrowsable(EditorBrowsableState.Never)]
public sealed class SqlAuthenticationProviderConfigurationSection : ConfigurationSection
Comment thread
paulmedynski marked this conversation as resolved.
Resolved
{
/// <include file='../doc/SqlAuthenticationProviderConfigurationSection.xml' path='docs/members[@name="SqlAuthenticationProviderConfigurationSection"]/Name/*'/>
public const string Name = "SqlAuthenticationProviders";

/// <include file='../doc/SqlAuthenticationProviderConfigurationSection.xml' path='docs/members[@name="SqlAuthenticationProviderConfigurationSection"]/Providers/*'/>
[ConfigurationProperty("providers")]
public ProviderSettingsCollection Providers => (ProviderSettingsCollection)this["providers"];

/// <include file='../doc/SqlAuthenticationProviderConfigurationSection.xml' path='docs/members[@name="SqlAuthenticationProviderConfigurationSection"]/InitializerType/*'/>
[ConfigurationProperty("initializerType")]
public string InitializerType => this["initializerType"] as string ?? string.Empty;

/// <include file='../doc/SqlAuthenticationProviderConfigurationSection.xml' path='docs/members[@name="SqlAuthenticationProviderConfigurationSection"]/ApplicationClientId/*'/>
[ConfigurationProperty("applicationClientId", IsRequired = false)]
public string ApplicationClientId => this["applicationClientId"] as string ?? string.Empty;

/// <include file='../doc/SqlAuthenticationProviderConfigurationSection.xml' path='docs/members[@name="SqlAuthenticationProviderConfigurationSection"]/UseWamBroker/*'/>
[ConfigurationProperty("useWamBroker", IsRequired = false)]
public string UseWamBroker => this["useWamBroker"] as string ?? string.Empty;
}

}
Original file line number Diff line number Diff line change
@@ -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
{
/// <include file='../doc/SqlClientAuthenticationProviderConfigurationSection.xml' path='docs/members[@name="SqlClientAuthenticationProviderConfigurationSection"]/SqlClientAuthenticationProviderConfigurationSection/*'/>
[EditorBrowsable(EditorBrowsableState.Never)]
public sealed class SqlClientAuthenticationProviderConfigurationSection : ConfigurationSection
{
/// <include file='../doc/SqlClientAuthenticationProviderConfigurationSection.xml' path='docs/members[@name="SqlClientAuthenticationProviderConfigurationSection"]/Name/*'/>
public const string Name = "SqlClientAuthenticationProviders";

/// <include file='../doc/SqlClientAuthenticationProviderConfigurationSection.xml' path='docs/members[@name="SqlClientAuthenticationProviderConfigurationSection"]/Providers/*'/>
[ConfigurationProperty("providers")]
public ProviderSettingsCollection Providers => (ProviderSettingsCollection)this["providers"];

/// <include file='../doc/SqlClientAuthenticationProviderConfigurationSection.xml' path='docs/members[@name="SqlClientAuthenticationProviderConfigurationSection"]/InitializerType/*'/>
[ConfigurationProperty("initializerType")]
public string InitializerType => this["initializerType"] as string ?? string.Empty;

/// <include file='../doc/SqlClientAuthenticationProviderConfigurationSection.xml' path='docs/members[@name="SqlClientAuthenticationProviderConfigurationSection"]/ApplicationClientId/*'/>
[ConfigurationProperty("applicationClientId", IsRequired = false)]
public string ApplicationClientId => this["applicationClientId"] as string ?? string.Empty;

/// <include file='../doc/SqlClientAuthenticationProviderConfigurationSection.xml' path='docs/members[@name="SqlClientAuthenticationProviderConfigurationSection"]/UseWamBroker/*'/>
[ConfigurationProperty("useWamBroker", IsRequired = false)]
public string UseWamBroker => this["useWamBroker"] as string ?? string.Empty;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// 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;

/// <summary>Pins authentication section names, configuration properties and defaults in Abstractions.</summary>
public class AuthenticationConfigurationSchemaTest
{
/// <summary>Both infrastructure-only handlers preserve their schema and remain hidden from IntelliSense.</summary>
[Theory]
[InlineData(typeof(SqlAuthenticationProviderConfigurationSection), "SqlAuthenticationProviders")]
[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<EditorBrowsableAttribute>(
Assert.Single(type.GetCustomAttributes(typeof(EditorBrowsableAttribute), inherit: false)));
Assert.Equal(EditorBrowsableState.Never, editorBrowsable.State);
var section = Assert.IsAssignableFrom<ConfigurationSection>(Activator.CreateInstance(type));
Assert.Equal(new[] { "applicationClientId", "initializerType", "providers", "useWamBroker" },
section.ElementInformation.Properties.Cast<PropertyInformation>()
.Select(property => property.Name).OrderBy(name => name, StringComparer.Ordinal));
Assert.IsType<ProviderSettingsCollection>(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);
}

#if NETFRAMEWORK
/// <summary>The net462 handlers use framework configuration without adding ConfigurationManager.</summary>
[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
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@
<PackageReference Include="System.Security.Cryptography.Pkcs" />
</ItemGroup>

<!-- Additional source files for GenAPI ============================== -->
<ItemGroup>
<!-- GenAPI does not reproduce forwards from the reference assembly. -->
<Compile Include="../src/TypeForwards.Abstractions.cs" Link="TypeForwards.Abstractions.cs" />
</ItemGroup>

<!-- Generate "Not Supported" Source ================================= -->
<PropertyGroup>
<NotSupportedSourceFile>$(AssemblyName).$(TargetFramework).notsupported.cs</NotSupportedSourceFile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,10 @@
<PackageReference Include="System.Text.Json" />
<PackageReference Include="System.Threading.Channels" />
</ItemGroup>

<!-- Additional source files for GenAPI ============================== -->
<ItemGroup>
<!-- GenAPI does not reproduce forwards from the reference assembly. -->
<Compile Include="../src/TypeForwards.Abstractions.cs" Link="TypeForwards.Abstractions.cs" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<dependency id="Microsoft.Data.SqlClient.SNI.runtime" version="$SniVersionRange$" exclude="Compile" />
<dependency id="Microsoft.Extensions.Caching.Memory" version="10.0.13" exclude="Compile" />
<dependency id="Microsoft.SqlServer.Server" version="$SqlServerVersionRange$" />
<dependency id="System.Configuration.ConfigurationManager" version="10.0.13" exclude="Compile" />
<dependency id="System.Configuration.ConfigurationManager" version="10.0.13" />
<dependency id="System.Security.Cryptography.Pkcs" version="10.0.13" />
<dependency id="System.Threading.RateLimiting" version="10.0.13" />
</group>
Expand All @@ -72,7 +72,7 @@
<dependency id="Microsoft.Data.SqlClient.SNI.runtime" version="$SniVersionRange$" exclude="Compile" />
<dependency id="Microsoft.Extensions.Caching.Memory" version="10.0.13" exclude="Compile" />
<dependency id="Microsoft.SqlServer.Server" version="$SqlServerVersionRange$" />
<dependency id="System.Configuration.ConfigurationManager" version="10.0.13" exclude="Compile" />
<dependency id="System.Configuration.ConfigurationManager" version="10.0.13" />
<dependency id="System.Security.Cryptography.Pkcs" version="10.0.13" />
<dependency id="System.Text.Json" version="10.0.13" />
<dependency id="System.Threading.Channels" version="10.0.13" />
Expand Down
Loading
Loading