Skip to content

Commit 29f639a

Browse files
Revert Resource API changes in SqlAuthenticationParameter (#231)
* Revert Resource API changes in SqlAuthenticationParameter * Generalize
1 parent 33bad3a commit 29f639a

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/ActiveDirectoryNativeAuthenticationProvider.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace Microsoft.Data.SqlClient
1414
/// </summary>
1515
internal class ActiveDirectoryNativeAuthenticationProvider : SqlAuthenticationProvider
1616
{
17+
private static readonly string s_defaultScopeSuffix = "/.default";
1718
private readonly string _type = typeof(ActiveDirectoryNativeAuthenticationProvider).Name;
1819

1920
/// <summary>
@@ -27,7 +28,8 @@ public override Task<SqlAuthenticationToken> AcquireTokenAsync(SqlAuthentication
2728
.WithClientVersion(Common.ADP.GetAssemblyVersion().ToString())
2829
.Build();
2930
AuthenticationResult result;
30-
string[] scopes = parameters.Scopes;
31+
string scope = parameters.Resource.EndsWith(s_defaultScopeSuffix) ? parameters.Resource : parameters.Resource + s_defaultScopeSuffix;
32+
string[] scopes = new string[] { scope };
3133

3234
// Note: CorrelationId, which existed in ADAL, can not be set in MSAL (yet?).
3335
// parameter.ConnectionId was passed as the CorrelationId in ADAL to aid support in troubleshooting.

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlAuthenticationParameters.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class SqlAuthenticationParameters
2222
/// <summary>
2323
/// Resource URI.
2424
/// </summary>
25-
public string[] Scopes { get; }
25+
public string Resource { get; }
2626

2727
/// <summary>
2828
/// Authority URI.
@@ -58,7 +58,7 @@ protected SqlAuthenticationParameters(
5858
SqlAuthenticationMethod authenticationMethod,
5959
string serverName,
6060
string databaseName,
61-
string[] scopes,
61+
string resource,
6262
string authority,
6363
string userId,
6464
string password,
@@ -67,7 +67,7 @@ protected SqlAuthenticationParameters(
6767
AuthenticationMethod = authenticationMethod;
6868
ServerName = serverName;
6969
DatabaseName = databaseName;
70-
Scopes = scopes;
70+
Resource = resource;
7171
Authority = authority;
7272
UserId = userId;
7373
Password = password;
@@ -82,7 +82,7 @@ internal class Builder
8282
private readonly SqlAuthenticationMethod _authenticationMethod;
8383
private readonly string _serverName;
8484
private readonly string _databaseName;
85-
private readonly string[] _scopes;
85+
private readonly string _resource;
8686
private readonly string _authority;
8787
private string _userId;
8888
private string _password;
@@ -97,7 +97,7 @@ public static implicit operator SqlAuthenticationParameters(Builder builder)
9797
authenticationMethod: builder._authenticationMethod,
9898
serverName: builder._serverName,
9999
databaseName: builder._databaseName,
100-
scopes: builder._scopes,
100+
resource: builder._resource,
101101
authority: builder._authority,
102102
userId: builder._userId,
103103
password: builder._password,
@@ -154,7 +154,7 @@ internal Builder(SqlAuthenticationMethod authenticationMethod, string resource,
154154
_authenticationMethod = authenticationMethod;
155155
_serverName = serverName;
156156
_databaseName = databaseName;
157-
_scopes = new string[] { resource + "/.default" };
157+
_resource = resource;
158158
_authority = authority;
159159
}
160160
}

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/ActiveDirectoryNativeAuthenticationProvider.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace Microsoft.Data.SqlClient
1414
/// </summary>
1515
internal class ActiveDirectoryNativeAuthenticationProvider : SqlAuthenticationProvider
1616
{
17+
private static readonly string s_defaultScopeSuffix = "/.default";
1718
private readonly string _type = typeof(ActiveDirectoryNativeAuthenticationProvider).Name;
1819
private readonly SqlClientLogger _logger = new SqlClientLogger();
1920

@@ -28,7 +29,8 @@ public override Task<SqlAuthenticationToken> AcquireTokenAsync(SqlAuthentication
2829
.WithClientVersion(Common.ADP.GetAssemblyVersion().ToString())
2930
.Build();
3031
AuthenticationResult result;
31-
string[] scopes = parameters.Scopes;
32+
string scope = parameters.Resource.EndsWith(s_defaultScopeSuffix) ? parameters.Resource : parameters.Resource + s_defaultScopeSuffix;
33+
string[] scopes = new string[] { scope };
3234

3335
// Note: CorrelationId, which existed in ADAL, can not be set in MSAL (yet?).
3436
// parameter.ConnectionId was passed as the CorrelationId in ADAL to aid support in troubleshooting.

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlAuthenticationParameters.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class SqlAuthenticationParameters
2222
/// <summary>
2323
/// Resource URI.
2424
/// </summary>
25-
public string[] Scopes { get; }
25+
public string Resource { get; }
2626

2727
/// <summary>
2828
/// Authority URI.
@@ -58,7 +58,7 @@ protected SqlAuthenticationParameters(
5858
SqlAuthenticationMethod authenticationMethod,
5959
string serverName,
6060
string databaseName,
61-
string[] scopes,
61+
string resource,
6262
string authority,
6363
string userId,
6464
string password,
@@ -67,7 +67,7 @@ protected SqlAuthenticationParameters(
6767
AuthenticationMethod = authenticationMethod;
6868
ServerName = serverName;
6969
DatabaseName = databaseName;
70-
Scopes = scopes;
70+
Resource = resource;
7171
Authority = authority;
7272
UserId = userId;
7373
Password = password;
@@ -82,7 +82,7 @@ internal class Builder
8282
private readonly SqlAuthenticationMethod _authenticationMethod;
8383
private readonly string _serverName;
8484
private readonly string _databaseName;
85-
private readonly string[] _scopes;
85+
private readonly string _resource;
8686
private readonly string _authority;
8787
private string _userId;
8888
private string _password;
@@ -97,7 +97,7 @@ public static implicit operator SqlAuthenticationParameters(Builder builder)
9797
authenticationMethod: builder._authenticationMethod,
9898
serverName: builder._serverName,
9999
databaseName: builder._databaseName,
100-
scopes: builder._scopes,
100+
resource: builder._resource,
101101
authority: builder._authority,
102102
userId: builder._userId,
103103
password: builder._password,
@@ -154,7 +154,7 @@ internal Builder(SqlAuthenticationMethod authenticationMethod, string resource,
154154
_authenticationMethod = authenticationMethod;
155155
_serverName = serverName;
156156
_databaseName = databaseName;
157-
_scopes = new string[] { resource + "/.default" };
157+
_resource = resource;
158158
_authority = authority;
159159
}
160160
}

0 commit comments

Comments
 (0)