-
Notifications
You must be signed in to change notification settings - Fork 330
AOT-safe auth provider with feature switch and trimmer support #4348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
paulmedynski
wants to merge
10
commits into
main
Choose a base branch
from
dev/paul/aot
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,034
−242
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
461a6db
feat: AOT-safe auth provider with feature switch and trimmer support
paulmedynski 54212ff
Address PR #4348 review feedback
paulmedynski 6c9eba2
Split ILLink substitutions into platform-specific files
paulmedynski 11d75ab
Address PR #4348 review feedback: conditional using, TFM-gated tests,…
paulmedynski 1abdfbd
Remove unused using directives flagged by PR review
paulmedynski 6038cb0
Unify ILLink substitutions per edwardneal's suggestion
paulmedynski 71f93d8
Merge branch 'main' into dev/paul/aot
paulmedynski f02279b
fix: address PR #4348 review feedback
paulmedynski feb9826
Remove public ApplicationClientId from SqlAuthenticationProviderManager
paulmedynski f1da5b1
Address PR #4348 copilot review feedback
paulmedynski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationProviderManager.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.