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..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,8 @@ public override Task AcquireTokenAsync(SqlAuthentication .WithClientVersion(Common.ADP.GetAssemblyVersion().ToString()) .Build(); AuthenticationResult result; - string[] scopes = parameters.Scopes; + 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?). // 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..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,8 @@ public override Task AcquireTokenAsync(SqlAuthentication .WithClientVersion(Common.ADP.GetAssemblyVersion().ToString()) .Build(); AuthenticationResult result; - string[] scopes = parameters.Scopes; + 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?). // 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; } }