Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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,68 @@
<!--
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>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>
<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>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>
</members>
</docs>
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
Condition="'$(ReferenceType)' == 'Project'" />
<PackageReference Include="Microsoft.Data.SqlClient.Internal.Logging"
Condition="'$(ReferenceType)' == 'Package'" />
<PackageReference Include="System.Configuration.ConfigurationManager"
Comment thread
cheenamalhotra marked this conversation as resolved.
Resolved
PrivateAssets="contentfiles;build;buildTransitive;analyzers" />
</ItemGroup>

<!-- CodeGen Targets ================================================= -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
<?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,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
{
/// <include file='../doc/SqlAuthenticationProviderConfigurationSection.xml' path='docs/members[@name="SqlAuthenticationProviderConfigurationSection"]/SqlAuthenticationProviderConfigurationSection/*'/>
[EditorBrowsable(EditorBrowsableState.Never)]
public class SqlAuthenticationProviderConfigurationSection : ConfigurationSection
{
/// <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;
}

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

/// <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)
{
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);
}
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -516,49 +516,6 @@ private static string GetProviderType(SqlAuthenticationProvider? provider)
}
}

/// <summary>
/// The configuration section definition for reading app.config.
/// </summary>
internal class SqlAuthenticationProviderConfigurationSection : ConfigurationSection
{
public const string Name = "SqlAuthenticationProviders";

/// <summary>
/// User-defined auth providers.
/// </summary>
[ConfigurationProperty("providers")]
public ProviderSettingsCollection Providers => (ProviderSettingsCollection)this["providers"];

/// <summary>
/// User-defined initializer.
/// </summary>
[ConfigurationProperty("initializerType")]
public string InitializerType => this["initializerType"] as string ?? string.Empty;

/// <summary>
/// Application Client Id
/// </summary>
[ConfigurationProperty("applicationClientId", IsRequired = false)]
public string ApplicationClientId => this["applicationClientId"] as string ?? string.Empty;

/// <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="bool.TryParse(string, out bool)"/>.
/// </summary>
[ConfigurationProperty("useWamBroker", IsRequired = false)]
public string UseWamBroker => this["useWamBroker"] as string ?? string.Empty;
}

/// <summary>
/// The configuration section definition for reading app.config.
/// </summary>
internal class SqlClientAuthenticationProviderConfigurationSection : SqlAuthenticationProviderConfigurationSection
{
public new const string Name = "SqlClientAuthenticationProviders";
}

/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationInitializer.xml' path='docs/members[@name="SqlAuthenticationInitializer"]/SqlAuthenticationInitializer/*'/>
public abstract class SqlAuthenticationInitializer
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@

namespace Microsoft.Data.SqlClient.UnitTests
{
/// <summary>Verifies relocated public types remain resolvable through the driver assembly.</summary>
public class TypeForwardTests
{
private static readonly Assembly s_sqlClientAssembly = typeof(SqlConnection).Assembly;

/// <summary>Type forwards preserve resolution through the original assembly name.</summary>
[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
Expand All @@ -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);
Expand Down
Loading