From 6aad085e62b71d916232c4727330e3b2f76c1c06 Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Thu, 26 Sep 2019 10:59:23 -0700 Subject: [PATCH 1/2] Revert Resource API changes in SqlAuthenticationParameter --- .../ActiveDirectoryNativeAuthenticationProvider.cs | 3 ++- .../Data/SqlClient/SqlAuthenticationParameters.cs | 12 ++++++------ .../ActiveDirectoryNativeAuthenticationProvider.cs | 3 ++- .../Data/SqlClient/SqlAuthenticationParameters.cs | 12 ++++++------ 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/ActiveDirectoryNativeAuthenticationProvider.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/ActiveDirectoryNativeAuthenticationProvider.cs index 5652d93f04..4a07fa9639 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/ActiveDirectoryNativeAuthenticationProvider.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/ActiveDirectoryNativeAuthenticationProvider.cs @@ -27,7 +27,8 @@ public override Task AcquireTokenAsync(SqlAuthentication .WithClientVersion(Common.ADP.GetAssemblyVersion().ToString()) .Build(); AuthenticationResult result; - string[] scopes = parameters.Scopes; + string scope = parameters.Resource.EndsWith("/.default") ? parameters.Resource : parameters.Resource + "./default"; + string[] scopes = new string[] { scope }; // Note: CorrelationId, which existed in ADAL, can not be set in MSAL (yet?). // parameter.ConnectionId was passed as the CorrelationId in ADAL to aid support in troubleshooting. diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlAuthenticationParameters.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlAuthenticationParameters.cs index c3b9b6c6f5..c66c2b6d68 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlAuthenticationParameters.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlAuthenticationParameters.cs @@ -22,7 +22,7 @@ public class SqlAuthenticationParameters /// /// Resource URI. /// - public string[] Scopes { get; } + public string Resource { get; } /// /// Authority URI. @@ -58,7 +58,7 @@ protected SqlAuthenticationParameters( SqlAuthenticationMethod authenticationMethod, string serverName, string databaseName, - string[] scopes, + string resource, string authority, string userId, string password, @@ -67,7 +67,7 @@ protected SqlAuthenticationParameters( AuthenticationMethod = authenticationMethod; ServerName = serverName; DatabaseName = databaseName; - Scopes = scopes; + Resource = resource; Authority = authority; UserId = userId; Password = password; @@ -82,7 +82,7 @@ internal class Builder private readonly SqlAuthenticationMethod _authenticationMethod; private readonly string _serverName; private readonly string _databaseName; - private readonly string[] _scopes; + private readonly string _resource; private readonly string _authority; private string _userId; private string _password; @@ -97,7 +97,7 @@ public static implicit operator SqlAuthenticationParameters(Builder builder) authenticationMethod: builder._authenticationMethod, serverName: builder._serverName, databaseName: builder._databaseName, - scopes: builder._scopes, + resource: builder._resource, authority: builder._authority, userId: builder._userId, password: builder._password, @@ -154,7 +154,7 @@ internal Builder(SqlAuthenticationMethod authenticationMethod, string resource, _authenticationMethod = authenticationMethod; _serverName = serverName; _databaseName = databaseName; - _scopes = new string[] { resource + "/.default" }; + _resource = resource; _authority = authority; } } diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/ActiveDirectoryNativeAuthenticationProvider.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/ActiveDirectoryNativeAuthenticationProvider.cs index daed2323e7..aaaa3ea09a 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/ActiveDirectoryNativeAuthenticationProvider.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/ActiveDirectoryNativeAuthenticationProvider.cs @@ -28,7 +28,8 @@ public override Task AcquireTokenAsync(SqlAuthentication .WithClientVersion(Common.ADP.GetAssemblyVersion().ToString()) .Build(); AuthenticationResult result; - string[] scopes = parameters.Scopes; + string scope = parameters.Resource.EndsWith("/.default") ? parameters.Resource : parameters.Resource + "./default"; + string[] scopes = new string[] { scope }; // Note: CorrelationId, which existed in ADAL, can not be set in MSAL (yet?). // parameter.ConnectionId was passed as the CorrelationId in ADAL to aid support in troubleshooting. diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlAuthenticationParameters.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlAuthenticationParameters.cs index c3b9b6c6f5..c66c2b6d68 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlAuthenticationParameters.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlAuthenticationParameters.cs @@ -22,7 +22,7 @@ public class SqlAuthenticationParameters /// /// Resource URI. /// - public string[] Scopes { get; } + public string Resource { get; } /// /// Authority URI. @@ -58,7 +58,7 @@ protected SqlAuthenticationParameters( SqlAuthenticationMethod authenticationMethod, string serverName, string databaseName, - string[] scopes, + string resource, string authority, string userId, string password, @@ -67,7 +67,7 @@ protected SqlAuthenticationParameters( AuthenticationMethod = authenticationMethod; ServerName = serverName; DatabaseName = databaseName; - Scopes = scopes; + Resource = resource; Authority = authority; UserId = userId; Password = password; @@ -82,7 +82,7 @@ internal class Builder private readonly SqlAuthenticationMethod _authenticationMethod; private readonly string _serverName; private readonly string _databaseName; - private readonly string[] _scopes; + private readonly string _resource; private readonly string _authority; private string _userId; private string _password; @@ -97,7 +97,7 @@ public static implicit operator SqlAuthenticationParameters(Builder builder) authenticationMethod: builder._authenticationMethod, serverName: builder._serverName, databaseName: builder._databaseName, - scopes: builder._scopes, + resource: builder._resource, authority: builder._authority, userId: builder._userId, password: builder._password, @@ -154,7 +154,7 @@ internal Builder(SqlAuthenticationMethod authenticationMethod, string resource, _authenticationMethod = authenticationMethod; _serverName = serverName; _databaseName = databaseName; - _scopes = new string[] { resource + "/.default" }; + _resource = resource; _authority = authority; } } From 8443576f21de9e10c724124d39e59fc136d3b861 Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Fri, 27 Sep 2019 13:21:20 -0700 Subject: [PATCH 2/2] Generalize --- .../SqlClient/ActiveDirectoryNativeAuthenticationProvider.cs | 3 ++- .../SqlClient/ActiveDirectoryNativeAuthenticationProvider.cs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/ActiveDirectoryNativeAuthenticationProvider.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/ActiveDirectoryNativeAuthenticationProvider.cs index 4a07fa9639..4f0f5165a5 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/ActiveDirectoryNativeAuthenticationProvider.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/ActiveDirectoryNativeAuthenticationProvider.cs @@ -14,6 +14,7 @@ namespace Microsoft.Data.SqlClient /// internal class ActiveDirectoryNativeAuthenticationProvider : SqlAuthenticationProvider { + private static readonly string s_defaultScopeSuffix = "/.default"; private readonly string _type = typeof(ActiveDirectoryNativeAuthenticationProvider).Name; /// @@ -27,7 +28,7 @@ public override Task AcquireTokenAsync(SqlAuthentication .WithClientVersion(Common.ADP.GetAssemblyVersion().ToString()) .Build(); AuthenticationResult result; - string scope = parameters.Resource.EndsWith("/.default") ? parameters.Resource : parameters.Resource + "./default"; + string scope = parameters.Resource.EndsWith(s_defaultScopeSuffix) ? parameters.Resource : parameters.Resource + s_defaultScopeSuffix; string[] scopes = new string[] { scope }; // Note: CorrelationId, which existed in ADAL, can not be set in MSAL (yet?). diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/ActiveDirectoryNativeAuthenticationProvider.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/ActiveDirectoryNativeAuthenticationProvider.cs index aaaa3ea09a..645d28e2c2 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/ActiveDirectoryNativeAuthenticationProvider.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/ActiveDirectoryNativeAuthenticationProvider.cs @@ -14,6 +14,7 @@ namespace Microsoft.Data.SqlClient /// internal class ActiveDirectoryNativeAuthenticationProvider : SqlAuthenticationProvider { + private static readonly string s_defaultScopeSuffix = "/.default"; private readonly string _type = typeof(ActiveDirectoryNativeAuthenticationProvider).Name; private readonly SqlClientLogger _logger = new SqlClientLogger(); @@ -28,7 +29,7 @@ public override Task AcquireTokenAsync(SqlAuthentication .WithClientVersion(Common.ADP.GetAssemblyVersion().ToString()) .Build(); AuthenticationResult result; - string scope = parameters.Resource.EndsWith("/.default") ? parameters.Resource : parameters.Resource + "./default"; + string scope = parameters.Resource.EndsWith(s_defaultScopeSuffix) ? parameters.Resource : parameters.Resource + s_defaultScopeSuffix; string[] scopes = new string[] { scope }; // Note: CorrelationId, which existed in ADAL, can not be set in MSAL (yet?).