Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'UpSream/master' into WriteAsyncCollision
# Conflicts: # src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNINpHandle.cs
- Loading branch information
Showing
478 changed files
with
6,635 additions
and
15,212 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,30 @@ | ||
//<Snippet1> | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.Identity.Client; | ||
using Microsoft.Data.SqlClient; | ||
|
||
namespace CustomAuthenticationProviderExamples | ||
{ | ||
public class Program | ||
{ | ||
public static void Main() | ||
{ | ||
SqlAuthenticationProvider authProvider = new ActiveDirectoryAuthenticationProvider(CustomDeviceFlowCallback); | ||
SqlAuthenticationProvider.SetProvider(SqlAuthenticationMethod.ActiveDirectoryDeviceCodeFlow, authProvider); | ||
using (SqlConnection sqlConnection = new SqlConnection("Server=<myserver>.database.windows.net;Authentication=Active Directory Device Code Flow;Database=<db>;")) | ||
{ | ||
sqlConnection.Open(); | ||
Console.WriteLine("Connected successfully!"); | ||
} | ||
} | ||
|
||
private static Task CustomDeviceFlowCallback(DeviceCodeResult result) | ||
{ | ||
// Provide custom logic to process result information and read device code. | ||
Console.WriteLine(result.Message); | ||
return Task.FromResult(0); | ||
} | ||
} | ||
} | ||
//</Snippet1> |
56 changes: 56 additions & 0 deletions
56
doc/samples/CustomDeviceCodeFlowAzureAuthenticationProvider.cs
This file contains 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,56 @@ | ||
//<Snippet1> | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.Identity.Client; | ||
using Microsoft.Data.SqlClient; | ||
|
||
namespace CustomAuthenticationProviderExamples | ||
{ | ||
/// <summary> | ||
/// Example demonstrating creating a custom device code flow authentication provider and attaching it to the driver. | ||
/// This is helpful for applications that wish to override the Callback for the Device Code Result implemented by the SqlClient driver. | ||
/// </summary> | ||
public class CustomDeviceCodeFlowAzureAuthenticationProvider : SqlAuthenticationProvider | ||
{ | ||
public override async Task<SqlAuthenticationToken> AcquireTokenAsync(SqlAuthenticationParameters parameters) | ||
{ | ||
string clientId = "my-client-id"; | ||
string clientName = "My Application Name"; | ||
string s_defaultScopeSuffix = "/.default"; | ||
|
||
string[] scopes = new string[] { parameters.Resource.EndsWith(s_defaultScopeSuffix) ? parameters.Resource : parameters.Resource + s_defaultScopeSuffix }; | ||
|
||
IPublicClientApplication app = PublicClientApplicationBuilder.Create(clientId) | ||
.WithAuthority(parameters.Authority) | ||
.WithClientName(clientName) | ||
.WithRedirectUri("https://login.microsoftonline.com/common/oauth2/nativeclient") | ||
.Build(); | ||
|
||
AuthenticationResult result = await app.AcquireTokenWithDeviceCode(scopes, | ||
deviceCodeResult => CustomDeviceFlowCallback(deviceCodeResult)).ExecuteAsync(); | ||
return new SqlAuthenticationToken(result.AccessToken, result.ExpiresOn); | ||
} | ||
|
||
public override bool IsSupported(SqlAuthenticationMethod authenticationMethod) => authenticationMethod.Equals(SqlAuthenticationMethod.ActiveDirectoryDeviceCodeFlow); | ||
|
||
private Task CustomDeviceFlowCallback(DeviceCodeResult result) | ||
{ | ||
Console.WriteLine(result.Message); | ||
return Task.FromResult(0); | ||
} | ||
} | ||
|
||
public class Program | ||
{ | ||
public static void Main() | ||
{ | ||
SqlAuthenticationProvider.SetProvider(SqlAuthenticationMethod.ActiveDirectoryDeviceCodeFlow, new CustomDeviceCodeFlowAzureAuthenticationProvider()); | ||
using (SqlConnection sqlConnection = new SqlConnection("Server=<myserver>.database.windows.net;Authentication=Active Directory Device Code Flow;Database=<db>;")) | ||
{ | ||
sqlConnection.Open(); | ||
Console.WriteLine("Connected successfully!"); | ||
} | ||
} | ||
} | ||
} | ||
//</Snippet1> |
This file contains 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 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 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.