-
Notifications
You must be signed in to change notification settings - Fork 330
Expand file tree
/
Copy pathSqlAuthenticationProviderManager.xml
More file actions
85 lines (83 loc) · 4.63 KB
/
Copy pathSqlAuthenticationProviderManager.xml
File metadata and controls
85 lines (83 loc) · 4.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<docs>
<members name="SqlAuthenticationProviderManager">
<SqlAuthenticationProviderManager>
<summary>
Manages authentication provider registration for SQL Server connections.
Provides methods to get and set <see cref="T:Microsoft.Data.SqlClient.SqlAuthenticationProvider" /> instances
for specific <see cref="T:Microsoft.Data.SqlClient.SqlAuthenticationMethod" /> values.
</summary>
<remarks>
<para>
The <see cref="M:Microsoft.Data.SqlClient.SqlAuthenticationProviderManager.GetProvider(Microsoft.Data.SqlClient.SqlAuthenticationMethod)" />
and <see cref="M:Microsoft.Data.SqlClient.SqlAuthenticationProviderManager.SetProvider(Microsoft.Data.SqlClient.SqlAuthenticationMethod,Microsoft.Data.SqlClient.SqlAuthenticationProvider)" />
methods are AOT-safe because they do not use reflection — providers are registered
via direct static method calls.
</para>
<para>
By default, the manager's static constructor performs reflection-based discovery of the
Azure authentication extension assembly. This is safe for JIT applications but incompatible
with NativeAOT trimming. To disable this discovery and make the manager fully AOT-compatible,
set the <c>Microsoft.Data.SqlClient.EnableReflectionBasedAuthenticationProviderDiscovery</c>
runtime configuration option to <see langword="false" /> at publish time, and register
providers explicitly using
<see cref="M:Microsoft.Data.SqlClient.SqlAuthenticationProviderManager.SetProvider(Microsoft.Data.SqlClient.SqlAuthenticationMethod,Microsoft.Data.SqlClient.SqlAuthenticationProvider)" />.
</para>
</remarks>
</SqlAuthenticationProviderManager>
<GetProvider>
<summary>
Gets the authentication provider registered for the specified authentication method.
</summary>
<param name="authenticationMethod">The authentication method to look up.</param>
<returns>
The registered <see cref="T:Microsoft.Data.SqlClient.SqlAuthenticationProvider" /> for the
specified method, or <see langword="null" /> if no provider is registered.
</returns>
</GetProvider>
<SetProvider>
<summary>
Registers an authentication provider for the specified authentication method.
</summary>
<param name="authenticationMethod">The authentication method to register a provider for.</param>
<param name="provider">The authentication provider to register.</param>
<returns>
<see langword="true" /> if the provider was registered successfully;
<see langword="false" /> if the authentication method has already been claimed
via application configuration and cannot be overridden.
</returns>
<exception cref="T:System.NotSupportedException">
Thrown if the provider does not support the specified authentication method.
</exception>
<remarks>
<para>
Providers registered via application configuration (app.config) cannot be replaced
by calling this method. In that case, this method returns <see langword="false" />.
</para>
<para>
If a provider was previously registered for the same method (not via app.config),
it will be replaced and its <see cref="M:Microsoft.Data.SqlClient.SqlAuthenticationProvider.BeforeUnload(Microsoft.Data.SqlClient.SqlAuthenticationMethod)" />
method will be called before the new provider's
<see cref="M:Microsoft.Data.SqlClient.SqlAuthenticationProvider.BeforeLoad(Microsoft.Data.SqlClient.SqlAuthenticationMethod)" />
method is invoked.
</para>
</remarks>
<example>
The following example demonstrates registering a provider for AOT applications.
Use the default constructor to authenticate with the built-in first-party application client ID:
<code language="c#">
// Uses the built-in 1st-party application client ID.
var provider = new ActiveDirectoryAuthenticationProvider();
SqlAuthenticationProviderManager.SetProvider(
SqlAuthenticationMethod.ActiveDirectoryDefault, provider);
</code>
Or supply a custom application client ID registered in your Entra ID tenant:
<code language="c#">
// Uses a custom application client ID.
var provider = new ActiveDirectoryAuthenticationProvider("your-app-client-id");
SqlAuthenticationProviderManager.SetProvider(
SqlAuthenticationMethod.ActiveDirectoryDefault, provider);
</code>
</example>
</SetProvider>
</members>
</docs>