-
Notifications
You must be signed in to change notification settings - Fork 330
Fix ActiveDirectoryInteractive authentication #3986
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
329c4e3
Task 42705: Investigate AD Interactive not working
paulmedynski f32ac4a
Task 42705: Investigate AD Interactive not working
paulmedynski 2fe1de0
Task 42705: Investigate AD Interactive not working
paulmedynski 5ccbc27
Task 42705: Investigate AD Interactive not working
paulmedynski 48061cb
Task 42705: Investigate AD Interactive not working
paulmedynski a7932d6
Task 42705: Investigate AD Interactive not working
paulmedynski 65addf6
Task 42705: Investigate AD Interactive not working
paulmedynski b409b16
Task 42705: Investigate AD Interactive not working
paulmedynski 94fe02a
Task 42705: Investigate AD Interactive not working
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
There are no files selected for viewing
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
69 changes: 69 additions & 0 deletions
69
src/Microsoft.Data.SqlClient.Extensions/Azure/test/ActiveDirectoryInteractiveTests.cs
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,69 @@ | ||
| // 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 Xunit.Abstractions; | ||
|
|
||
| namespace Microsoft.Data.SqlClient.Extensions.Azure.Test; | ||
|
|
||
| public class ActiveDirectoryInteractiveTests | ||
| { | ||
| private readonly ITestOutputHelper _output; | ||
|
|
||
| public ActiveDirectoryInteractiveTests(ITestOutputHelper output) | ||
| { | ||
| _output = output; | ||
| } | ||
|
|
||
| [Fact] | ||
| [Trait("Category", "Interactive")] | ||
|
paulmedynski marked this conversation as resolved.
paulmedynski marked this conversation as resolved.
|
||
| public async Task TestConnection() | ||
| { | ||
| SqlConnectionStringBuilder builder = new() | ||
| { | ||
| // This is an Azure SQL database accessible via MSFT-AzVPN. | ||
| // | ||
| // To successfully login, you must add your EntraID identity to the database using | ||
| // commands like this: | ||
| // | ||
| // use [Northwind]; | ||
| // create user [<you>@microsoft.com] from external provider; | ||
| // alter role db_datareader add member [paulmedynski@microsoft.com]; | ||
|
paulmedynski marked this conversation as resolved.
Outdated
|
||
| // | ||
| // You must connect to the database as an admin in order run these commands, for example | ||
| // as the testodbc@microsoft.com user via SQL username/password authentication. | ||
| // | ||
| DataSource = "adotest.database.windows.net", | ||
| InitialCatalog = "Northwind", | ||
| Encrypt = true, | ||
| TrustServerCertificate = false, | ||
| ConnectTimeout = 180, | ||
| Authentication = SqlAuthenticationMethod.ActiveDirectoryInteractive | ||
| }; | ||
|
|
||
| var connection = new SqlConnection(builder.ConnectionString); | ||
|
|
||
| try | ||
| { | ||
| connection.Open(); | ||
|
paulmedynski marked this conversation as resolved.
Outdated
paulmedynski marked this conversation as resolved.
Outdated
|
||
| } | ||
| catch (SqlException ex) | ||
| { | ||
| _output.WriteLine($"Exception: {ex}"); | ||
|
|
||
| // SqlException doesn't emit all of its errors via its ToString(), so we must do that | ||
| // ourselves if we want to see everything. | ||
| // | ||
| // SqlErrorCollection doesn't support foreach, so we have to iterate by hand to get | ||
| // properly typed SqlError instances. | ||
| // | ||
| for (int i = 0; i < ex.Errors.Count; i++) | ||
| { | ||
| _output.WriteLine($"Error[{i}]: {ex.Errors[i].ToString()}"); | ||
| } | ||
|
|
||
| // Re-throw to fail the test. | ||
| throw; | ||
| } | ||
| } | ||
| } | ||
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.
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.