Skip to content

Commit

Permalink
Revert Resource API changes in SqlAuthenticationParameter (#231)
Browse files Browse the repository at this point in the history
* Revert Resource API changes in SqlAuthenticationParameter

* Generalize
  • Loading branch information
cheenamalhotra committed Sep 27, 2019
1 parent 33bad3a commit 29f639a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
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

0 comments on commit 29f639a

Please sign in to comment.