Skip to content

Commit 7ff600e

Browse files
Allow username with Active Directory Interactive Authentication (#492)
1 parent 98834fc commit 7ff600e

File tree

6 files changed

+12
-11
lines changed

6 files changed

+12
-11
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public override Task<SqlAuthenticationToken> AcquireTokenAsync(SqlAuthentication
5252
{
5353
result = await app.AcquireTokenInteractive(scopes)
5454
.WithUseEmbeddedWebView(true)
55+
.WithLoginHint(parameters.UserId)
5556
.ExecuteAsync();
5657
}
5758

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,9 +530,9 @@ internal SqlConnectionString(string connectionString) : base(connectionString, G
530530
throw SQL.IntegratedWithUserIDAndPassword();
531531
}
532532

533-
if (Authentication == SqlAuthenticationMethod.ActiveDirectoryInteractive && (HasUserIdKeyword || HasPasswordKeyword))
533+
if (Authentication == SqlAuthenticationMethod.ActiveDirectoryInteractive && (HasPasswordKeyword))
534534
{
535-
throw SQL.InteractiveWithUserIDAndPassword();
535+
throw SQL.InteractiveWithPassword();
536536
}
537537

538538
#if ADONET_CERT_AUTH

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,9 @@ static internal Exception IntegratedWithUserIDAndPassword()
326326
return ADP.Argument(StringsHelper.GetString(Strings.SQL_IntegratedWithUserIDAndPassword));
327327
}
328328

329-
static internal Exception InteractiveWithUserIDAndPassword()
329+
static internal Exception InteractiveWithPassword()
330330
{
331-
return ADP.Argument(StringsHelper.GetString(Strings.SQL_InteractiveWithUserIDAndPassword));
331+
return ADP.Argument(StringsHelper.GetString(Strings.SQL_InteractiveWithPassword));
332332
}
333333

334334
static internal Exception SettingIntegratedWithCredential()

src/Microsoft.Data.SqlClient/netfx/src/Resources/Strings.Designer.cs

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Microsoft.Data.SqlClient/netfx/src/Resources/Strings.resx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2496,8 +2496,8 @@
24962496
<data name="SQL_IntegratedWithUserIDAndPassword" xml:space="preserve">
24972497
<value>Cannot use 'Authentication=Active Directory Integrated' with 'User ID', 'UID', 'Password' or 'PWD' connection string keywords.</value>
24982498
</data>
2499-
<data name="SQL_InteractiveWithUserIDAndPassword" xml:space="preserve">
2500-
<value>Cannot use 'Authentication=Active Directory Interactive' with 'User ID', 'UID', 'Password' or 'PWD' connection string keywords.</value>
2499+
<data name="SQL_InteractiveWithPassword" xml:space="preserve">
2500+
<value>Cannot use 'Authentication=Active Directory Interactive' with 'Password' or 'PWD' connection string keywords.</value>
25012501
</data>
25022502
<data name="SQL_SettingIntegratedWithCredential" xml:space="preserve">
25032503
<value>Cannot use 'Authentication=Active Directory Integrated', if the Credential property has been set.</value>

src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ConnectivityTests/AADConnectionTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,14 @@ public static void IntegratedAuthWithCred()
224224

225225
[ConditionalFact(nameof(IsAADConnStringsSetup))]
226226
[SkipOnTargetFramework(TargetFrameworkMonikers.Netcoreapp)]
227-
public static void MFAAuthWithCred()
227+
public static void MFAAuthWithPassword()
228228
{
229229
// connection fails with expected error message.
230230
string[] AuthKey = { "Authentication" };
231231
string connStr = DataTestUtility.RemoveKeysInConnStr(DataTestUtility.AADPasswordConnectionString, AuthKey) + "Authentication=Active Directory Interactive;";
232232
ArgumentException e = Assert.Throws<ArgumentException>(() => ConnectAndDisconnect(connStr));
233233

234-
string expectedMessage = "Cannot use 'Authentication=Active Directory Interactive' with 'User ID', 'UID', 'Password' or 'PWD' connection string keywords.";
234+
string expectedMessage = "Cannot use 'Authentication=Active Directory Interactive' with 'Password' or 'PWD' connection string keywords.";
235235
Assert.Contains(expectedMessage, e.Message);
236236
}
237237

0 commit comments

Comments
 (0)