Skip to content
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

Revert Resource API changes in SqlAuthenticationParameter #231

Merged
merged 2 commits into from
Sep 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Microsoft.Data.SqlClient
/// </summary>
internal class ActiveDirectoryNativeAuthenticationProvider : SqlAuthenticationProvider
{
private static readonly string s_defaultScopeSuffix = "/.default";
private readonly string _type = typeof(ActiveDirectoryNativeAuthenticationProvider).Name;

/// <summary>
Expand All @@ -27,7 +28,8 @@ public override Task<SqlAuthenticationToken> 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class SqlAuthenticationParameters
/// <summary>
/// Resource URI.
/// </summary>
public string[] Scopes { get; }
public string Resource { get; }

/// <summary>
/// Authority URI.
Expand Down Expand Up @@ -58,7 +58,7 @@ protected SqlAuthenticationParameters(
SqlAuthenticationMethod authenticationMethod,
string serverName,
string databaseName,
string[] scopes,
string resource,
string authority,
string userId,
string password,
Expand All @@ -67,7 +67,7 @@ protected SqlAuthenticationParameters(
AuthenticationMethod = authenticationMethod;
ServerName = serverName;
DatabaseName = databaseName;
Scopes = scopes;
Resource = resource;
Authority = authority;
UserId = userId;
Password = password;
Expand All @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Microsoft.Data.SqlClient
/// </summary>
internal class ActiveDirectoryNativeAuthenticationProvider : SqlAuthenticationProvider
{
private static readonly string s_defaultScopeSuffix = "/.default";
private readonly string _type = typeof(ActiveDirectoryNativeAuthenticationProvider).Name;
private readonly SqlClientLogger _logger = new SqlClientLogger();

Expand All @@ -28,7 +29,8 @@ public override Task<SqlAuthenticationToken> 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class SqlAuthenticationParameters
/// <summary>
/// Resource URI.
/// </summary>
public string[] Scopes { get; }
public string Resource { get; }

/// <summary>
/// Authority URI.
Expand Down Expand Up @@ -58,7 +58,7 @@ protected SqlAuthenticationParameters(
SqlAuthenticationMethod authenticationMethod,
string serverName,
string databaseName,
string[] scopes,
string resource,
string authority,
string userId,
string password,
Expand All @@ -67,7 +67,7 @@ protected SqlAuthenticationParameters(
AuthenticationMethod = authenticationMethod;
ServerName = serverName;
DatabaseName = databaseName;
Scopes = scopes;
Resource = resource;
Authority = authority;
UserId = userId;
Password = password;
Expand All @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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;
}
}
Expand Down